入门小菜鸟的学习笔记,希望大佬们帮忙纠错啦~侵权立删。
解法一:
import numpy as np
x = np.array([[1,2,3],[4,5,6],[7,8,9]])
y = np.array([[1,2,1],[2,1,1],[1,1,2]])
R = np.multiply(x,y)
print("x=\n",x)
print("y=\n",y)
print("矩阵对应元素相乘的结果为:\n",R)
运行结果:
解法二:
import numpy as np
mat1 = np.mat([[1,2,3],[2,3,4],[4,5,6]])
mat2 = np.mat([[1,2,3],[2,1,4],[4,1,6]])
mat3 = np.mat([[0,0,0],[0,0,0],[0,0,0]])
for i in range(3):
for j in range(3):
mat3[i,j] = mat1[i,j]*mat2[i,j]
mat3
运行结果:
个人学习笔记,仅供参考,如有错误,请多指正。