I was wondering if there were any situation where a numpy array owning its data is stored non-contiguously.
From a numerical point of view, non-contiguous, row- or column-aligned buffers make sense and are ubiquitous in performance libraries such as IPP. However it seems that numpy by default converts anything passed as an argument of array
to a contiguous buffer. This is not really explicitly said in the documentation as far as I understand it.
My question is, does numpy guarantee that any owning array created with np.array
is contiguous in memory? More generally, in which situations can we come across a non-contiguous owning array?
EDIT following @Eelco's answer
By non-contiguous, I mean that there is some "empty spaces" in the memory chunk used to store data (strides[1] > shape[0] * itemsize
if you will). I do not mean an array whose data is stored using two or more memory allocations — I would be surprised that such an owning numpy array exists. This seems to be consistent with numpy's terminology according to this answer.
By owning arrays, I mean arrays whose .flags.owndata=True
. I am not interested in non-owning arrays who can behave wildly indeed.