diag

paddle.fluid.layers.tensor. diag ( diagonal ) [source]

Warning: API “paddle.fluid.layers.tensor.diag” is deprecated since 2.0.0, and will be removed in future versions. Please use “paddle.diag” instead.

alias_main

paddle.diag

alias

paddle.diag,paddle.tensor.diag,paddle.tensor.creation.diag

old_api

paddle.fluid.layers.diag

This OP creates a square matrix which has diagonal values specified by input diagonal.

Args:
diagonal(Variable|numpy.ndarray): The input tensor should be 1D tensor, the input shape is \([ N]\) ,

specifying diagonal values by this input tensor. The input data type should be float32, float64, int32, int64.

Returns:
Variable, the output data type is the same as input data type.: The tensor variable storing the square matrix,

the diagonal values specified by input diagonal. the output shape is \([N, N]\) with two dims.

Examples:
# [[3, 0, 0]
#  [0, 4, 0]
#  [0, 0, 5]

import paddle.fluid as fluid
import numpy as np
diagonal = np.arange(3, 6, dtype='int32')
data = fluid.layers.diag(diagonal)
# diagonal.shape=(3,) data.shape=(3, 3)