ValueError: matmul: Input operand 1 does not have enough dimensions (has 0, gufunc core with ...)

在进行矩阵乘法的时候,报以下错误:

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] 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值