E:\ana\envs\dl\python.exe E:\pythonProject\ADMM\wienen.py Traceback (most recent call last): File "E:\pythonProject\A

动态 未结 0 87
小小草
小小草 LV1 2023年9月23日 23:40 发表
这个错误是由于在计算 `Z` 的时候,`composite_index` 和 `weights` 的维度不匹配导致的。具体来说,`composite_index` 是一个长度为 248576 的一维数组,而 `weights` 是一个长度为 11 的一维数组,无法直接相加。 可以尝试将 `weights` 转换成一个长度为 248576 的一维数组,使得它和 `composite_index` 的维度匹配。可以使用以下代码来实现: ```python weights = np.repeat(weights, len(composite_index) // len(weights)) weights = np.concatenate([weights, np.zeros(len(composite_index) % len(weights))]) ``` 在上面的代码中,首先使用 `np.repeat` 函数将 `weights` 数组重复多次,使得它的长度和 `composite_index` 相同。然后使用 `np.concatenate` 函数将 `weights` 和一些零值拼接起来,使得它的长度恰好等于 `composite_index` 的长度。 修改完代码后再次运行程序,应该就能够成功运行了。
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复