# numpy.triu () in Python

|

numpy.triu (a, k = 0): returns a copy of the array with the top of the triangle relative to 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 Programming Illustrative ` ` # NumPy. trio method `   ` import ` ` numpy as geek `   ` # input line ` ` a ` ` = ` ` geek.matrix ([[` ` 1 ` `, ` ` 21 ` `, ` ` 30 ` `], ` ` [` ` 63 ` `, ` ` 434 ` `, ` ` 3 ` `], ` ` [` ` 54 ` `, ` ` 54 ` `, ` ` 56 ` ]])   ` print ` ` (` ` "Main Diagonal elements:" ` `, geek. triu (a), ` ` "" ` `) `   ` print ` ` (` `" Diagonal above main Diagonal elements: "` `, geek. triu (a, ` ` 1 ` `) , ` ` "" ` `) `   ` print ` ` (` ` "Main Diagonal elements:" ` `, geek. triu (a, ` ` - ` ` 1 ` `)) `

Exit :

``` 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]]    Link:    https://docs.scipy.org/doc/numpy/reference/generated/numpy.triu.html#numpy.triu    Notes:   These programs NumPy-Python will not work by network id, so run them on your systems to examine them ,  This article is provided by  Mohit Gupta_OMG

```

## Shop Learn programming in R: courses

\$ Best Python online courses for 2022

\$ Best laptop for Fortnite

\$ Best laptop for Excel

\$ Best laptop for Solidworks

\$ Best laptop for Roblox

\$ Best computer for crypto mining

\$ Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

NUMPYNUMPY

How to convert Nonetype to int or string?

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

## Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method