-
-
Notifications
You must be signed in to change notification settings - Fork 12.8k
DEP: Deprecate setting the shape attribute of a numpy array #29536
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
Changes from all commits
98264cb
27ef5f2
b7842a8
9af1e83
1695917
1d71fc5
e8cbd57
354a04e
bea4884
5c8a65e
914462d
7e06ce2
2e80bf0
d49ab1e
37d1b42
b888253
5576aa2
5de80b9
0ff8bb0
f096794
1a237cf
198e62a
f739d54
87a45e7
e51276d
f45274e
96e029b
48cdec4
9482110
2ed9a48
bfed477
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Setting the ``shape`` attribute is deprecated | ||
| --------------------------------------------- | ||
| Setting the shape attribute is now deprecated since mutating | ||
| an array is unsafe if an array is shared, especially by multiple | ||
| threads. As an alternative, you can create a new view via | ||
| `np.reshape` or `np.ndarray.reshape`. For example: ``x = np.arange(15); x = np.reshape(x, (3, 5))``. | ||
| To ensure no copy is made from the data, one can use ``np.reshape(..., copy=False)``. | ||
|
|
||
| Directly setting the shape on an array is discouraged, but for cases where it is difficult to work | ||
| around, e.g., in ``__array_finalize__`` possible with the private method `np.ndarray._set_shape`. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5183,8 +5183,8 @@ def meshgrid(*xi, copy=True, sparse=False, indexing='xy'): | |
|
|
||
| if indexing == 'xy' and ndim > 1: | ||
| # switch first and second axis | ||
| output[0].shape = (1, -1) + s0[2:] | ||
| output[1].shape = (-1, 1) + s0[2:] | ||
| output[0] = output[0].reshape((1, -1) + s0[2:]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd tend to instead generate
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still think if makes more sense to do, But I can also see that you want to minimize changes... |
||
| output[1] = output[1].reshape((-1, 1) + s0[2:]) | ||
|
|
||
| if not sparse: | ||
| # Return the full N-D matrix (not only the 1-D vector) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.