numpy.triu() in Python Last Updated : 09 Mar, 2022 Comments Improve Suggest changes Like Article Like Report numpy.triu(a, k = 0) : Returns copy of array with upper part of the triangle w.r.t k Parameters : a : input array k : [int, optional, 0 by default] Diagonal we require; k>0 means diagonal above main diagonal or vice versa. Returns : Upper triangle of a, having same shape and data-type as a. Python # Python Programming illustrating # numpy. triu method import numpy as geek # string input a = geek.matrix([[1, 21, 30], [63 ,434, 3], [54, 54, 56]]) print("Main Diagonal elements : \n", geek. triu(a), "\n") print("Diagonal above main Diagonal elements : \n", geek. triu(a, 1), "\n\n") print("Main Diagonal elements : \n", geek. triu(a, -1)) Output : Main Diagonal elements : [[ 1 21 30] [ 0 434 3] [ 0 0 56]] Diagonal above main Diagonal elements : [[ 0 21 30] [ 0 0 3] [ 0 0 0]] Main Diagonal elements : [[ 1 21 30] [ 63 434 3] [ 0 54 56]] Reference : https://docs.scipy.org/doc/numpy/reference/generated/numpy.triu.html#numpy.triu Note : These NumPy-Python programs won't run on online IDE's, so run them on your systems to explore them. Comment More infoAdvertise with us Next Article numpy.triu() in Python M Mohit Gupta_OMG Improve Article Tags : Misc Python Python-numpy Python numpy-arrayCreation Practice Tags : Miscpython Similar Reads numpy.tri() in Python numpy.tri(R, C = None, k = 0, dtype = 'float') : Creates an array with 1's at and below the given diagonal(about k) and 0's elsewhere. Parameters : R : Number of rows C : [optional] Number of columns; By default R = C k : [int, optional, 0 by default] Diagonal we require; k>0 means diagonal above 2 min read numpy.tril() in Python numpy.tril(a, k=0) : Returns copy of array with lower part of the triangle w.r.t k Parameters : a : input array k : [int, optional, 0 by default] Diagonal we require; k>0 means diagonal above main diagonal or vice versa. Returns : Lower triangle of a, having same shape and data-type as a. Python 1 min read numpy.tan() in Python numpy.tan(array[, out]) = ufunc 'tan') : This mathematical function helps user to calculate trigonometric tangent for all x(being the array elements). Parameters : array : [array_like]elements are in radians. out : [optional]shape same as array. 2pi Radians = 360 degrees tan(x) = sin(x) / cos(x) Ret 2 min read numpy.sin() in Python numpy.sin(x[, out]) = ufunc 'sin') : This mathematical function helps user to calculate trigonometric sine for all x(being the array elements). Parameters : array : [array_like]elements are in radians. 2pi Radians = 36o degrees Return : An array with trigonometric sine of x for all x i.e. array elem 1 min read numpy.sinh() in Python The numpy.sinh() is a mathematical function that helps user to calculate hyperbolic sine for all x(being the array elements). Equivalent to 1/2 * (np.exp(x) - np.exp(-x)) or -1j * np.sin(1j*x). Syntax: numpy.sinh(x[, out]) = ufunc 'sin') Parameters : array : [array_like] elements are in radians. 2pi 2 min read numpy.sinc() in Python numpy.sinc(array) : This mathematical function helps user to calculate sinc function for all x(being the array elements). Parameters : array : [array_like] elements are in radians. 2pi Radians = 36o degrees Return : An array with sinc value of x for all x i.e. array elements. Code #1 : Working Pytho 1 min read numpy.tanh() in Python The numpy.tanh()is a mathematical function that helps user to calculate hyperbolic tangent for all x(being the array elements). Equivalent to np.sinh(x) / np.cosh(x) or -1j * np.tan(1j*x). Syntax : numpy.tanh(x[, out]) = ufunc 'tanh') Parameters : array : [array_like] elements are in radians. 2pi Ra 2 min read Python | Numpy np.triu_indices With the help of np.triu_indices() method, we can get the indices for the upper triangle of an [n, m] array by using np.triu_indices() method. Syntax : np.triu_indices(n, m) Return : Return the indices for the upper triangle. Example #1 : In this example we can see that by using np.triu_indices() me 1 min read numpy.cos() in Python numpy.cos(x[, out]) = ufunc 'cos') : This mathematical function helps user to calculate trigonometric cosine for all x(being the array elements). Parameters : array : [array_like]elements are in radians. 2pi Radians = 360 degrees Return : An array with trigonometric cosine of x for all x i.e. array 2 min read numpy.cosh() in Python The numpy.cosh() is a mathematical function that helps user to calculate hyperbolic cosine for all x(being the array elements). Equivalent to 1/2 * (np.exp(x) - np.exp(-x)) and np.cos(1j*x). Syntax : numpy.cosh(x[, out]) = ufunc 'cos') Parameters : array : [array_like] elements are in radians. 2pi R 2 min read Like