Is numpy.transpose reordering data in memory?

后端 未结 2 1053
余生分开走
余生分开走 2021-01-01 16:11

In order to speed up the functions like np.std, np.sum etc along an axis of an n dimensional huge numpy array, it is recommended to apply along the last axis.

When I

2条回答
  •  旧时难觅i
    2021-01-01 16:46

    Transpose just changes the strides, it doesn't touch the actual array. I think the reason why sum etc. along the final axis is recommended (I'd like to see the source for that, btw.) is that when an array is C-ordered, walking along the final axis preserves locality of reference. That won't be the case after you transpose, since the transposed array will be Fortran-ordered.

提交回复
热议问题