-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to grow array by assigning a size-1 array to a size-0 slice doesn't throw exception #11309
Comments
Thanks for reporting. Seems like a bug to me. |
This is broadcasting, and works for the same reason as: x[:10] = [1]
x[:1] = [1]
x[:0] = [1] |
Well, it may seem a bit strange, but correct by broadcasting rules, since 1 can be broadcast to 0. In fact, it suddenly all makes sense if you think about it:
and then decide |
I suppose the documentation I cited needs to add a link, and the broadcasting page needs to mention that it considers assignment an operation, but documentation sucks as a resource anyway ... modifying the exception message would be far more help (though the fact that the exception even can be different smells of copypasta). Honestly, I'm more confused now than before, w.r.t. broadcasting. I've only ever used it with a different number of axes (e.g. If I ever had wanted to do something like that, I would (and probably did, sometime) call As it is, the sloppiness feels purely like a design bug that's too late to change. Did somebody say something like "There should be 3, and preferably more than 3, counterintuitive ways to do it"? |
Frankly, there is one way, and it is broadcasting whether you like it the implicit zero stride allowed for 1 sized dimensions or not. Or since we are citing, another way to put it:
So, unless you are dutch, lets agree it is in the eye of the beholder. Building a 0 strided array is definitely not the intended (or obvious) way in most cases, and using Obviously you are right, we are stuck with it, but I think broadcasting is one of those thing generally considered a big step in the right direction. The docs (and error messages) can always use improvements, although I am not sure where the inconsistency in the error messages is exactly. (I am sure it is there, there are plenty of really very different things that look similar, and some of those would be nice to consolidate. Those are things that generally happen, albeit slowly, unless someone steps up and does it). |
Per documentation:
(aside: the documentation could mention "never grow (or shrink)")
However, instead of throwing an exception, the following code silently does nothing.
Other cases correctly throw the exception:
Discovered with numpy 1.12.1 from Debian, but verified with numpy 1.14.4 from PyPI.
The text was updated successfully, but these errors were encountered: