import numpy as np
import matplotlib.pyplot as plt
# 定义矩阵
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
# 矩阵的四则运算
addition = A + B
subtraction = A - B
multiplication = A * B
division = A / B
# 带变元的矩阵计算
x = 9
scalar_multiplication = A * x
# 特征值和特征向量的计算
eigenvalues, eigenvectors = np.linalg.eig(A)
# 可视化矩阵A
plt.imshow(A, cmap='magma')
plt.colorbar(label='Value')
plt.title('Matrix A')
plt.xticks(np.arange(A.shape[1]))
plt.yticks(np.arange(A.shape[0]))
plt.grid(True, color='gray', linestyle='dotted')
plt.show()
# 打印结果
print("矩阵A:")
print(A)
print("\n矩阵B:")
print(B)
print("\n加法结果:")
print(addition)
print("\n减法结果:")
print(subtraction)
print("\n逐元素乘法结果:")
print(multiplication)
print("\n逐元素除法结果:")
print(division)
print("\n带变元的乘法结果:")
print(scalar_multiplication)
print("\n矩阵A的特征值:")
print(eigenvalues)
print("\n矩阵A的特征向量:")
print(eigenvectors)
可以可视化
标签:plt,multiplication,运算,结果,矩阵,np,print From: https://www.cnblogs.com/yunbianshangdadun/p/17499246.html