numpy.tri

numpy.tri(N, M=None, k=0, dtype=<type 'float'>)

Construct an array filled with ones at and below the given diagonal.

Parameters:

N : int

Number of rows in the array.

M : int, optional

Number of columns in the array. By default, M is taken equal to N.

k : int, optional

The sub-diagonal below which the array is filled. k = 0 is the main diagonal, while k < 0 is below it, and k > 0 is above. The default is 0.

dtype : dtype, optional

Data type of the returned array. The default is float.

Returns:

T : (N,M) ndarray

Array with a lower triangle filled with ones, in other words T[i,j] == 1 for i <= j + k.

Examples

>>> 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.]])

Previous topic

numpy.diagflat

Next topic

numpy.tril

This Page

Quick search