Best_bless 2023-02-01 14:53 采纳率: 40%
浏览 10

遇到value error,操作数与张量无法广播,该如何解决?

本人在构建预测网店销售额的模型的最后一步中遇到问题,查错显示value error :operands could not be broadcast together with shape (3, ) (4, ),知道原因,但不知道怎么修改,从哪里下手,还请高人为小辈指点迷津,感激不尽!
报错代码如图所示:

img

  • 写回答

2条回答 默认 最新

  • m0_54204465 2023-02-01 15:04
    关注

    ValueError: operands could not be broadcast together with shapes (3,)(4,)说明在计算np.dot()的点积时,X_plan的形状(3,)与weight_history的形状(4,)不匹配。

    可以考虑以下几种方法来解决这个问题:

    将X_plan转换为与weight_history相同的形状,例如:

    X_plan = np.array(X_plan)
    X_plan = np.reshape(X_plan, (len(X_plan), 1))
    
    

    将weight_history转换为与X_plan相同的形状,例如:

    
    weight_history = np.array(weight_history)
    weight_history = np.reshape(weight_history, (1, len(weight_history)))
    

    请确保执行的操作与您的代码适合。最后,请检查其他函数(例如scaler())是否有任何影响,并进行必要的修改。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月1日