[Numpy-discussion] Will transpose ever need to copy data?
Jaime Fernández del Río
Tue Jun 11 11:24:08 CDT 2013
I noticed today that the documentation for np.transpose states, for the
return value, that "A view is returned whenever possible."
Is there really any situation where swapping axes around could trigger the
need to copy data, or will a view always be returned no matter what?
I can't think of any such situation, and was planning on relying on that
for some code: basically, I have an output array, which I would like to be
contiguous. So I preallocate it with the right shape, then take a view of
it moving a certain axis to the end to make computations easier, run all my
computations on the modified view, then return the original array, not the
If I started with an array with the axis at the end, and then transposed
it, I would need to make a copy to make it contiguous, which is what I am
trying to avoid.
Is this a bad practice? Is that precaution in the documentation real?
Should I check that my view's base is the original array and trigger a
copy, or is it an unnecessary check?
Thanks in advance,
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
de dominación mundial.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion