An array with ones at and below the given diagonal and zeros elsewhere. 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
(N, M=None, k=0, dtype=float, *, like=None)
| 390 | @finalize_array_function_like |
| 391 | @set_module('numpy') |
| 392 | def tri(N, M=None, k=0, dtype=float, *, like=None): |
| 393 | """ |
| 394 | An array with ones at and below the given diagonal and zeros elsewhere. |
| 395 | |
| 396 | Parameters |
| 397 | ---------- |
| 398 | N : int |
| 399 | Number of rows in the array. |
| 400 | M : int, optional |
| 401 | Number of columns in the array. |
| 402 | By default, `M` is taken equal to `N`. |
| 403 | k : int, optional |
| 404 | The sub-diagonal at and below which the array is filled. |
| 405 | `k` = 0 is the main diagonal, while `k` < 0 is below it, |
| 406 | and `k` > 0 is above. The default is 0. |
| 407 | dtype : dtype, optional |
| 408 | Data type of the returned array. The default is float. |
| 409 | ${ARRAY_FUNCTION_LIKE} |
| 410 | |
| 411 | .. versionadded:: 1.20.0 |
| 412 | |
| 413 | Returns |
| 414 | ------- |
| 415 | tri : ndarray of shape (N, M) |
| 416 | Array with its lower triangle filled with ones and zero elsewhere; |
| 417 | in other words ``T[i,j] == 1`` for ``j <= i + k``, 0 otherwise. |
| 418 | |
| 419 | Examples |
| 420 | -------- |
| 421 | >>> import numpy as np |
| 422 | >>> np.tri(3, 5, 2, dtype=np.int_) |
| 423 | array([[1, 1, 1, 0, 0], |
| 424 | [1, 1, 1, 1, 0], |
| 425 | [1, 1, 1, 1, 1]]) |
| 426 | |
| 427 | >>> np.tri(3, 5, -1) |
| 428 | array([[0., 0., 0., 0., 0.], |
| 429 | [1., 0., 0., 0., 0.], |
| 430 | [1., 1., 0., 0., 0.]]) |
| 431 | |
| 432 | """ |
| 433 | |
| 434 | warning_for_type = None |
| 435 | try: |
| 436 | N = operator.index(N) |
| 437 | except TypeError: |
| 438 | warning_for_type = warning_for_type or type(N) |
| 439 | |
| 440 | if like is not None: |
| 441 | return _tri_with_like(like, N, M=M, k=k, dtype=dtype) |
| 442 | |
| 443 | if M is None: |
| 444 | M = N |
| 445 | else: |
| 446 | try: |
| 447 | M = operator.index(M) |
| 448 | except TypeError: |
| 449 | warning_for_type = warning_for_type or type(M) |