在进行矩阵乘法的时候,报以下错误:
ValueError: matmul: Input operand 1 does not have enough dimensions (has 0, gufunc core with signature (n?,k), (k,m?) -> (n?,m?) requires 1)
在博客https://blog.csdn.net/m0_37881992/article/details/106500071中,提到是scipy的banben太高导致的,但是在终端和conda平台尝试多次降低scipy版本都失败了。后来我想到了一个办法,不调用np.matmul,而是改为代码直接计算两个矩阵相乘。
根据:
A=[[1,2,3],[4,5,6]]
A = np.array(A)
B=[[1,2,3],[4,5,6],[7,8,9]]
B=np.array(B)
result = [[sum(a * b for a, b in zip(A_row, B_col)) for B_col in zip(*B)] for A_row in A]
将 R = np.matmul(A,B) ,改为:
R = [[sum(a * b for a, b in zip(A_row, B_col)) for B_col in zip(*B)] for A_row in A]