求矩阵C=A*B的python代码,使用了numpy。
import numpy as np
a = np.array([
[1, 2, 3],
[3, 4, 5],
[6, 7, 8]
])
b = np.array([
[5, 6, 7],
[7, 8, 9],
[1, 2, 3]
])
c = np.zeros_like(a) #c=a*b
nx = a.shape[0]
for i in range(nx):
for j in range(nx):
c[i][j] = 0;
for k in range(nx):
c[i][j] = c[i][j] + a[i][k]*b[k][j]
print a*b
print c