Do numpy views store pointers or float objects?
I am trying to use numpy sliding view to perform something without pandas
arr =np.lib.stride_tricks.sliding_window_view(
(np.arange(510)), (50), axis=0
)
This arr
is a read-only object, but is it using the same amount of memory as an ndarray?
Apparently .nbytes
returns the same, but
from sys import getsizeof
getsizeof(arr)
# Returns 128
getsizeof(arr.copy())
# Returns 184528
What is happening here?
=======================Edit=======================
- related question: How much memory is used by the underlying buffer of a broadcasted numpy array?
- numpy docs: https://numpy.org/devdocs/reference/generated/numpy.lib.stride_tricks.sliding_window_view.html
@juanpa has pointed out views share the same underlying buffer.
AFAI understand, it means views are pass-by-reference