mars.tensor.identity

mars.tensor.identity(n, dtype=None, sparse=False, gpu=False, chunk_size=None)[source]

Return the identity tensor.

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

n : int
Number of rows (and columns) in n x n output.
dtype : data-type, optional
Data-type of the output. Defaults to float.
sparse: bool, optional
Create sparse tensor if True, False as default
gpu : bool, optional
Allocate the tensor on GPU if True, False as default
chunks : int or tuple of int or tuple of ints, optional
Desired chunk size on each dimension
out : Tensor
n x n array with its main diagonal set to one, and all other elements 0.
>>> import mars.tensor as mt
>>> mt.identity(3).execute()
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])