numpy.tri
numpy.tri(N, M=None, k=0, dtype=) [source]
在给定对角线处及以下且在其他位置为零的数组。
参数 : | N : 数组中的行数。 M : 数组中的列数。 默认情况下,M等于N。 k : 填充数组并在其下的对角线。 而 dtype : 返回数组的数据类型。 默认为 |
返回值 : | tri :ndarray of shape (N, M) 下三角的数组由1填充,在其他地方为0; 换句话说,对于 |
例子
>>> np.tri(3, 5, 2, dtype=int) array([[1, 1, 1, 0, 0], [1, 1, 1, 1, 0], [1, 1, 1, 1, 1]])
>>> np.tri(3, 5, -1) array([[0., 0., 0., 0., 0.], [1., 0., 0., 0., 0.], [1., 1., 0., 0., 0.]])