mindspore.numpy.tril

mindspore.numpy.tril(m, k=0)[源代码]

Returns a lower triangle of a tensor.

Returns a copy of a tensor with elements above the k-th diagonal zeroed.

参数
  • m (Union[Tensor, list, tuple]) – The shape and data-type of m define these same attributes of the returned tensor.

  • k (int, optional) – Diagonal above which to zero elements. \(k = 0\) (the default) is the main diagonal, \(k < 0\) is below it and \(k > 0\) is above.

返回

Lower triangle of m, of same shape and data-type as m.

Supported Platforms:

Ascend GPU CPU

异常
  • TypeError – If input arguments have types not specified above.

  • ValueError – If input m's rank \(< 1\).

样例

>>> import mindspore.numpy as np
>>> output = np.tril(np.ones((3, 3)))
>>> print(output)
[[1. 0. 0.]
[1. 1. 0.]
[1. 1. 1.]]