eye

paddle.fluid.layers.eye(num_rows, num_columns=None, batch_shape=None, dtype='float32')[source]

eye

This function constructs an identity tensor, or a batch of tensor.

Parameters
  • num_rows (int) – the number of rows in each batch tensor.

  • num_columns (int) – the number of columns in each batch tensor. If None, default: num_rows.

  • batch_shape (list(int)) – If provided, the returned tensor will have a leading batch size of this shape.

  • dtype (string) – The data type of the returned tensor. It should be int32, int64, float16, float32, float64.

Returns

An identity Tensor or LoDTensor of shape batch_shape + [num_rows, num_columns].

Return type

Variable

Examples

import paddle.fluid as fluid
data = fluid.layers.eye(3, dtype='int32')
# [[1, 0, 0]
#  [0, 1, 0]
#  [0, 0, 1]]

data = fluid.layers.eye(2, 3, dtype='int32')
# [[1, 0, 0]
#  [0, 1, 0]]

data = fluid.layers.eye(2, batch_shape=[3])
# Construct a batch of 3 identity tensors, each 2 x 2.
# data[i, :, :] is a 2 x 2 identity tensor, i = 0, 1, 2.