python 生成对称矩阵_对称矩阵之和| 使用Python的线性代数

python 生成对称矩阵

Prerequisite:

先决条件:

  • Defining Matrix using Numpy

    使用Numpy定义矩阵

  • Symmetric Matrices

    对称矩阵

Here, we will learn how to create two symmetric matrices and will add them? Adding two symmetric matrices results in a symmetric matrix.

在这里,我们将学习如何创建两个对称矩阵并将它们相加? 将两个对称矩阵相加得到一个对称矩阵。

S0 = S1 + S2

S 0 = S 1 + S 2

Note: The dimensions of S1 and S2 are same!

注意: S 1S 2的尺寸相同!

Example:

例:

python 生成对称矩阵_对称矩阵之和| 使用Python的线性代数_第1张图片

Python代码查找对称矩阵之和 (Python code to find sum of symmetric matrices)

# Linear Algebra Learning Sequence
# Addition of two symmetric Matrix

import numpy as np

M1 = np.array([[2,3,4], [3,5,4], [2,7,2], [1,3,2]])
M2 = np.array([[2,3,3], [3,2,7], [3,4,2], [3,2,1]])


S1 = np.matmul(M1,M1.T)
S2 = np.matmul(M2,M2.T)

print('\n\nS1\n', S1)
print('\n\nS2\n', S2)

# Adding S1 and S2
print('\n\nS1 + S2\n', S1+S2)

Output:

输出:



S1
 [[29 37 33 19]
 [37 50 49 26]
 [33 49 57 27]
 [19 26 27 14]]


S2
 [[22 33 24 15]
 [33 62 31 20]
 [24 31 29 19]
 [15 20 19 14]]


S1 + S2
 [[ 51  70  57  34]
 [ 70 112  80  46]
 [ 57  80  86  46]
 [ 34  46  46  28]]


翻译自: https://www.includehelp.com/python/sum-of-symmetric-matrices.aspx

python 生成对称矩阵

你可能感兴趣的:(python,机器学习,tensorflow,numpy,人工智能)