mars.tensor.identity#

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

返回单位张量。

单位张量是一个主对角线为1的平方数组。

Parameters
  • n (int) – n x n 输出中的行数(和列数)。

  • dtype (数据类型, 可选) – 输出的数据类型。默认为 float

  • 稀疏 (布尔值, 可选) – 如果为真则创建稀疏张量,默认为假

  • gpu (bool, 可选) – 如果为True,则在GPU上分配张量,默认为False

  • chunks (inttupleinttupleints, 可选) – 每个维度上所需的块大小

Returns

输出n x n 数组,其主对角线设置为1,其他所有元素为0。

Return type

张量

示例

>>> import mars.tensor as mt
>>> mt.identity(3).execute()
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])