我有两个矩阵,大小如下m=(15715203)n=(20316384)。我正在用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
目前没有回答
相关问题 更多 >
编程相关推荐