我有两个矩阵,其大小为m =(15715,203)n =(203,16384)。我在python中进行矩阵乘法,代码如图所示我使用canopy软件运行此代码但在完成之前它正在占用大量的内存空间并且崩溃请有人帮忙解决这个问题吗?
import pandas as pd
m = pd.read_csv("Pmatrix.csv")
row0=m.shape[0]
len0=len(m.columns)
print row0
print len0
n = pd.read_csv("Qmatrix.csv")
row1=n.shape[0]
len1=len(n.columns)
print row1
print len1
def matrixmult (A, B):
row0 = m.shape[0]
len0 = len(m.columns)
row1 = n.shape[0]
len1 = len(n.columns)
if len0 != row1:
print "Cannot multiply the two matrices. Incorrect dimensions."
Y=A.shape
Z=B.shape
print Y
print Z
return
# Create the result matrix
# Dimensions would be row0 x len1
C = [[0 for row in range(len1)] for col in range(row0)]
print C
for i in range(row0):
for j in range(len1):
for k in range(len0):
C[i][j] += A[i][k] * B[k][j]
return C