I have a buffer, dtype, shape and strides. I want to create a Numpy ndarray which reuses the memory of the buffer.
numpy.frombuffer which creates a 1D array from a buffer and reuses the memory. However, I'm not sure if I can easily and safely reshape it and set the strides.
There is the
numpy.ndarray constructor which can refer to a buffer but I'm not sure if it will reuse the memory or if it will copy it (it's not clear from the documentation).
So, will the
numpy.ndarray constructor do what I want? Or what can I use instead?
Ok, so I'm trying to figure out myself now what the
numpy.ndarray constructor is really doing. The code is here. It uses
PyArray_BufferConverter to convert the buffer argument. Then it will call
PyArray_NewFromDescr_int which can be seen here. If data is passed in there, it will
fa->flags &= ~NPY_ARRAY_OWNDATA;.