There are a few questions on SO about checking whether the numpy.reshape
call has returned a copy or not [1, 2]. These questions are generally posed due to the vague warning from the doc that:
This will be a new view object if possible; otherwise, it will be a copy.
What I'm wondering is in what circumstances will NumPy return a copy? In every 2D reshape
call I've tested, the method from user jterrace's answer in 2 shows that the memory base is the same (i.e. not a copy). Is it only for higher dimensional reshape
that a copy may be necessary?
Additionally, the second part of the warning from the docs informs the user that:
...there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.
In other words, you may ask for row-major, but you could get column-major output. Doesn't that defeat the whole purpose of the order
parameter? When would this case arise?