python矩阵中插入矩阵
The sum of diagonal elements of a matrix is commonly known as the trace of the matrix. It is mainly used in eigenvalues and other matrix applications. In this article, we are going to find the trace of a matrix using inbuilt function numpy.trace(a).
矩阵的对角元素之和通常称为矩阵的迹线。 它主要用于特征值和其他矩阵应用中。 在本文中,我们将使用内置函数numpy.trace(a)查找矩阵的轨迹 。
Python代码查找矩阵的痕迹 (Python code to find trace of a matrix)
# Linear Algebra Learning Sequence
# Trace of matrix
import numpy as np
print('Trace of an 3x3 identity matrix : ', np.trace(np.eye(3)))
a = np.arange(9).reshape((3,3))
print(' Matrix a :\n', a)
print('Trace of Matrix a : ', np.trace(a))
Output:
输出:
Trace of an 3x3 identity matrix : 3.0
Matrix a :
[[0 1 2]
[3 4 5]
[6 7 8]]
Trace of Matrix a : 12
翻译自: https://www.includehelp.com/python/trace-of-a-matrix.aspx
python矩阵中插入矩阵