BetterDocs
Home
Docs

Creation | np.triu()

This method is similar to np.tril()  .

Method:

np.triu(m, k=0)

Extracts the upper triangular part of an array.

Returns:

np.ndarray

Parameters:

m: array-like-

The input matrix.

import numpy as np
matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
result = np.triu(m=matrix, k=0)
print(result)
'''
Output:
[[1 2 3]
 [0 5 6]
 [0 0 9]]
'''

k: int, Optional-

The diagonal offset (default 0). A positive value refers to an upper diagonal, and a negative value to a lower diagonal.

k = 0 (default) +

k = 1 +

k = -1 +


Logo

BetterDocs

Support

EmailDiscordForms

Documentations

Python

Company

AboutDocs

Policies

Terms of ServicePrivacy Policy