-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
DOC: Clarify (potentially misleading) nbytes docstring #28943
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2676,10 +2676,14 @@ | |
|
||
add_newdoc('numpy._core.multiarray', 'ndarray', ('nbytes', | ||
""" | ||
Total bytes consumed by the elements of the array. | ||
Total number of bytes the array's data would consume if stored | ||
contiguously in memory. | ||
|
||
Notes | ||
----- | ||
If the array is a view, this shows how much memory it *would* use | ||
if it were copied into a separate array. | ||
|
||
Does not include memory consumed by non-element attributes of the | ||
array object. | ||
|
||
|
@@ -2698,6 +2702,17 @@ | |
>>> np.prod(x.shape) * x.itemsize | ||
480 | ||
|
||
>>> import numpy as np | ||
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. No need I think, but a sentence on why the next thing comes would help. |
||
>>> arr = np.arange(100).reshape(10, 10, 1) | ||
>>> arr_1 = np.broadcast_to(arr, (10, 10, 1000)) | ||
>>> arr_2 = np.lib.stride_tricks.sliding_window_view(arr, 5, 0) | ||
>>> arr.nbytes | ||
800 | ||
>>> arr_1.nbytes | ||
800000 | ||
>>> arr_2.nbytes | ||
2400 | ||
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. This introduces way too much complexity for very little gain. If anything at all, just do some slicing like |
||
|
||
""")) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we ca add that it also doesn't include memory indirectly held by the elements.
(I.e. if you store Python objects or the new
StringDType
)