-
-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Closed
Closed
Copy link
Description
In the following example I am using setitem to assign array values to a subset of an existing array. The subset to be assigned has shape (4, 2). Assume that by accident I am setting with an array of (2, 4), then I get an error:
In [6]: arr = np.arange(12).reshape(4, 3)
In [7]: arr[:, [1, 2]] = np.arange(8).reshape(2, 4)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-1f9697e767d9> in <module>
----> 1 arr[:, [1, 2]] = np.arange(8).reshape(2, 4)
ValueError: shape mismatch: value array of shape (2,4) could not be broadcast to indexing result of shape (2,4)
But the error message is a bit confusing: it seems to have swapped to order of the dimensions in the shape? (it says it could not be broadcast to (2, 4), instead of (4,2) ?)
1.20.0 3.8.6 | packaged by conda-forge | (default, Nov 27 2020, 19:31:52)
[GCC 9.3.0]
Reactions are currently unavailable