python 生成对称矩阵
Prerequisites:
先决条件:
Defining a matrix
定义矩阵
Identity matrix
身份矩阵
Transpose matrix
转置矩阵
In linear algebra, if the matrix and its transpose are equal, then the matrix is symmetric (MT = M).
在线性代数中,如果矩阵及其转置相等,则矩阵是对称的(MT = M) 。
In terms of elements of matrices: M(i, j) = M(j, i)
根据矩阵的元素: M(i,j)= M(j,i)
Following is a python code for demonstrating how to check for Symmetric Matrix.
以下是用于演示如何检查对称矩阵的python代码。
Method:
方法:
Syntax:
M = numpy.array( )
transpose_M = M.T
if transpose_M == M:
Transpose = True
Return:
MT
对称矩阵的Python代码 (Python code for symmetric matrices)
# Linear Algebra Learning Sequence
# Transpose using different Method
import numpy as np
M = np.array([[2,3,4], [3,45,8], [4,8,78]])
print("---Matrix M---\n", M)
# Transposing the Matrix M
print('\n\nTranspose as M.T----\n', M.T)
if M.T.all() == M.all():
print("--------> Transpose is eqaul to M")
M = np.array([[2,3,4], [3,45,8]])
print("\n\n---Matrix B---\n", M)
# Transposing the Matrix M
print('\n\nTranspose as B.T----\n', M.T)
if M.T.all() == M.all() and np.shape(M) == np.shape(M.T):
print("---------> Transpose is eqaul to B")
else:
print("---------> Not Transpose!!")
Output:
输出:
---Matrix M---
[[ 2 3 4]
[ 3 45 8]
[ 4 8 78]]
Transpose as M.T----
[[ 2 3 4]
[ 3 45 8]
[ 4 8 78]]
--------> Transpose is eqaul to M
---Matrix B---
[[ 2 3 4]
[ 3 45 8]]
Transpose as B.T----
[[ 2 3]
[ 3 45]
[ 4 8]]
---------> Not Transpose!!
翻译自: https://www.includehelp.com/python/symmetric-matrices.aspx
python 生成对称矩阵