numpy.tril() in Python (original) (raw)
Last Updated : 09 Mar, 2022
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.
import
numpy as geek
a
=
geek.matrix([[
1
,
21
,
30
],
`` [
63
,
434
,
3
],
`` [
54
,
54
,
56
]])
print
(
"Main Diagonal elements : \n"
, geek.tril(a),
"\n"
)
print
(
"Diagonal above main Diagonal elements : \n"
, geek.tril(a,
1
),
"\n\n"
)
print
(
"Main Diagonal elements : \n"
, geek.tril(a,
-
1
))
Output :
Main Diagonal elements : [[ 1 0 0] [ 63 434 0] [ 54 54 56]]
Diagonal above main Diagonal elements : [[ 1 21 0] [ 63 434 3] [ 54 54 56]]
Main Diagonal elements : [[ 0 0 0] [63 0 0] [54 54 0]]
References:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.tril.html#numpy.tril
Note :
These NumPy-Python programs won’t run on online IDE’s, so run them on your systems to explore them
.
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.triu() in Python 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. # Pyt 1 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.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.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 # Pyt 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.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
- numpy.sqrt() in Python numpy.sqrt() in Python is a function from the NumPy library used to compute the square root of each element in an array or a single number. It returns a new array of the same shape with the square roots of the input values. The function handles both positive and negative numbers, returning NaN for n 2 min read
- numpy.reciprocal() in Python The numpy.reciprocal() is a mathematical function that is used to calculate reciprocal of all the elements in the input array. Syntax :numpy.reciprocal(x, /, out=None, *, where=True) Parameters : x[array_like]: Input array or object whose elements needed to test. out [ndarray, optional]: A location 2 min read
- numpy.zeros() in Python numpy.zeros() function creates a new array of specified shapes and types, filled with zeros. It is beneficial when you need a placeholder array to initialize variables or store intermediate results. We can create 1D array using numpy.zeros(). Let's understand with the help of an example: [GFGTABS] P 2 min read