-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Proposal: add an optional copy argument to np.reshape #9818
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
Comments
Always agreed with that, the only slight annoyance is that we need yet another C-API version probably. |
Yep, this seems like a very good idea to me too. |
Agreed too, the only reason I use assignments to shape is because in some cases I want to be absolutely sure there won't be a copy for a very large array. I can similarly see the use of being able to ensure a copy is in fact made. |
@mhvk and the fun thing is, it does not really help you (except in the sense of an assert statement), because the shape assignment actually does the copy, then sees its a copy and raises an error. EDIT: Just to note, I am not sure if we have to Deprecate it, but we still need to discourage it in the docs, its a bad habit, but dunno if there might be a handful of actual use cases. |
ISTM that reshape can also replace ravel. |
Note that we will need to make sure that this doesn't break current subclasses of ndarray that do not implement the new keyword. |
True, about ravel, there is a problem with ravel, in that it makes sure that the output array is contiguous, which was a regression we once had and because someone (maybe scipy/some scikit) relied on it I think. |
On the C-API side, I suppose it would make sense to use enums here rather PyObject for the extra argument? e.g., |
Inspired by my discussion with @charris in #9810, I would like to propose adding an optional
copy
argument tonp.reshape()
andndarray.reshape()
.Proposed semantics:
copy=None
: copy only if necessary (default).copy=True
: always copy.copy=False
: never copy. Raise an error if the data cannot be reshaped without a copy.This would allow users to ensure desired behavior for
reshape
and alleviate the primary use case for modifyingndarray.shape
.The text was updated successfully, but these errors were encountered: