{ } Raw JSON

bundles / numpy 2.4.4 / numpy / triu

_ArrayFunctionDispatcher

numpy:triu

source: /numpy/lib/_twodim_base_impl.py :510

Signature

def   triu ( m k = 0 )

Summary

Upper triangle of an array.

Extended Summary

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.

Examples

import numpy as np
np.triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1)
np.triu(np.arange(3*4*5).reshape(3, 4, 5))

See also

tril

lower triangle of an array

Aliases

  • numpy.triu