ValueError: non-broadcastable output operand with shape (21,1) doesn't match the broadcast shape (21,60)
时间: 2024-05-09 15:21:23 浏览: 216
This error occurs when you are trying to perform an operation that involves broadcasting arrays, but the shapes of the arrays are not compatible for broadcasting.
In this specific case, it seems that you are trying to assign an array of shape (21, 1) to an array of shape (21, 60), which is not possible because the shapes are not compatible for broadcasting.
To fix this error, you need to reshape one of the arrays so that its shape is compatible with the other array. For example, you can reshape the (21, 1) array to (21, 60) by repeating the values in each row:
```
import numpy as np
# Example arrays
a = np.random.rand(21, 1)
b = np.random.rand(21, 60)
# Reshape 'a' to have shape (21, 60)
a_reshaped = np.tile(a, (1, 60))
# Now you can perform the operation without the ValueError
c = a_reshaped * b
```
In this example, `np.tile()` is used to repeat the values in each row of `a` 60 times, resulting in an array of shape (21, 60) that can be multiplied element-wise with `b`.
阅读全文