ivy.identity(n, dtype_str='float32', batch_shape=None, dev_str=None, f=None)[source]

Returns the identity array. The identity array is a square array with ones on the main diagonal.

  • n (int) – Number of rows (and columns) in n x n output.

  • dtype_str (data-type string, optional) – The desired data-type for the array in string format, i.e. ‘float32’ or ‘int64’. Default is ‘float32’.

  • batch_shape (sequence of ints, optional) – Shape of batch. Inferred from inputs if None.

  • dev_str (str) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc..

  • f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.


n x n array of type dtype_str, with its main diagonal set to one, and all other elements 0.

Supported Frameworks:

empty jax_logo empty tf_logo empty pytorch_logo empty mxnet_logo empty numpy_logo empty