Have a question? Connect with the community at the TensorFlow Forum

# TensorDiag

public final class TensorDiag

Returns a diagonal tensor with a given diagonal values.

Given a `diagonal`, this operation returns a tensor with the `diagonal` and everything else padded with zeros. The diagonal is computed as follows:

Assume `diagonal` has dimensions [D1,..., Dk], then the output is a tensor of rank 2k with dimensions [D1,..., Dk, D1,..., Dk] where:

`output[i1,..., ik, i1,..., ik] = diagonal[i1, ..., ik]` and 0 everywhere else.

For example:

``````# 'diagonal' is [1, 2, 3, 4]
tf.diag(diagonal) ==> [[1, 0, 0, 0]
[0, 2, 0, 0]
[0, 0, 3, 0]
[0, 0, 0, 4]]
``````

### Constants

 String OP_NAME The name of this op, as known by TensorFlow core engine

### Public Methods

 Output () Returns the symbolic handle of the tensor. static TensorDiag ( Scope scope, Operand diagonal) Factory method to create a class wrapping a new TensorDiag operation. Output ()

## Constants

#### public static final String OP_NAME

The name of this op, as known by TensorFlow core engine

Constant Value: "Diag"

## Public Methods

#### public Output <T> asOutput ()

Returns the symbolic handle of the tensor.

Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is used to obtain a symbolic handle that represents the computation of the input.

#### public static TensorDiag <T> create ( Scope scope, Operand <T> diagonal)

Factory method to create a class wrapping a new TensorDiag operation.

##### Parameters
 scope current scope Rank k tensor where k is at most 1.
##### Returns
• a new instance of TensorDiag

#### public Output <T> output ()

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]