{"id":27530,"date":"2022-08-14T14:27:20","date_gmt":"2022-08-14T08:57:20","guid":{"rendered":"https:\/\/python-programs.com\/?p=27530"},"modified":"2022-08-14T14:27:20","modified_gmt":"2022-08-14T08:57:20","slug":"python-numpy-matrix-diagonal-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-numpy-matrix-diagonal-function\/","title":{"rendered":"Python Numpy matrix.diagonal() Function"},"content":{"rendered":"

NumPy Library\u00a0<\/strong><\/p>\n

NumPy is a library in python that is created to work efficiently with arrays in python. It is fast, easy to learn, and provides efficient storage. It also provides a better way of handling data for the process. We can create an n-dimensional array in NumPy. To use NumPy simply have to import it into our program and then we can easily use the functionality of NumPy in our program.<\/p>\n

NumPy is a Python library that is frequently used for scientific and statistical analysis. NumPy arrays are grids of the same datatype\u2019s values.<\/p>\n

Numpy matrix.diagonal() Function:<\/strong><\/p>\n

We can find a diagonal element from a given matrix using the Numpy matrix.diagonal() method, which returns a one-dimensional matrix as output.<\/p>\n

Syntax:<\/strong><\/p>\n

 matrix.diagonal()<\/pre>\n

Return Value:<\/strong><\/p>\n

The diagonal element of a given matrix is returned by the diagonal() function.<\/p>\n

Numpy matrix.diagonal() Function in Python<\/h2>\n

For 2-Dimensional (2D) Matrix<\/strong><\/p>\n

Approach:<\/strong><\/p>\n