numpy. triu — NumPy v2. 3 Manual numpy triu# numpy triu (m, k = 0) [source] # Upper triangle of an array Return a copy of an array with the elements below the k-th diagonal zeroed For arrays with ndim exceeding 2, triu will apply to the final two axes Please refer to the documentation for tril for further details
torch. triu — PyTorch 2. 7 documentation torch triu (input, diagonal = 0, *, out = None) → Tensor ¶ Returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input , the other elements of the result tensor out are set to 0
Extract upper or lower triangular part of a numpy matrix Try numpy triu (triangle-upper) and numpy tril (triangle-lower) Code example: np triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]]) array([[ 1, 2, 3], [ 4, 5, 6], [ 0, 8, 9], [ 0, 0, 12]])
Exploring the numpy triu Method in Python – Be on the Right . . . - Finxter The simplest use of the numpy triu method involves passing just the matrix from which you want to extract the upper triangle By default, numpy triu includes the main diagonal and all elements above it, effectively setting the lower triangle to zero
triu — SciPy v1. 15. 3 Manual scipy sparse triu (A, k = 0, format = None) [source] # Return the upper triangular portion of a sparse array or matrix Returns the elements on or above the k-th diagonal of A
jax. numpy. triu — JAX documentation - Read the Docs jax numpy triu# jax numpy triu (m, k = 0) [source] # Return upper triangle of an array JAX implementation of numpy triu() Parameters: m (ArrayLike) – input array Must have m ndim >= 2 k – optional, int, default=0 Specifies the sub-diagonal below which the elements of the array are set to zero