mars.tensor.identity#
- mars.tensor.identity(n, dtype=None, sparse=False, gpu=None, chunk_size=None)[源代码]#
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 – n x n array with its main diagonal set to one, and all other elements 0.
- 返回类型
Tensor
实际案例
>>> import mars.tensor as mt
>>> mt.identity(3).execute() array([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]])