python对⾓线矩阵_Python矩阵的对⾓线
python 对⾓线矩阵
Some problems in linear algebra are mainly concerned with diagonal elements of the matrix. For this purpose, we have a predefined function numpy.diag(a) in NumPy library package which automatically stores diagonal elements in an array (a Vector). In this article, we are going to print the diagonal elements of a matrix using inbuilt function numpy.diag(a).
线性代数中的⼀些问题主要与矩阵的对⾓线元素有关。 为此,我们在NumPy库包中提供了预定义的函数numpy.diag(a),该函数⾃动将对⾓线元素存储在数组(向量)中。 在本⽂中,我们将使⽤内置函数numpy.diag(a)打印矩阵的对⾓线元素。
Python代码查矩阵的对⾓线 (Python code to find diagonal of a matrix)
# Linear Algebra Learning Sequence
# Diagonal of matrix
import numpy as np
print('Diagonal of an 3x3 identity matrix : ', np.(3)))
a = np.arange(9).reshape((3,3))
print(' Matrix a : ', a)
print('Diagonal of Matrix a : ', np.diag(a))
Output:
输出:
Diagonal of an 3x3 identity matrix : [1. 1. 1.]
Matrix a : [[0 1 2]identity matrix是什么意思
[3 4 5]
[6 7 8]]
Diagonal of Matrix a : [0 4 8]
翻译⾃:
python 对⾓线矩阵
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论