Description
Includes code, explanations and questions from StackOverflow
Summary
- Master stride tricks with 25 illustrated exercises Includes code, explanations and questions from StackOverflow The stride tricks API can be seen as an extension of the usual way of accessing and manipulating NumPyndarray’s, giving users more flexibility to control the resulting NumPy view.
- For the purpose of this article, it is recommended that the reader have mid-level knowledge of Python, NumPy, numpy.dtype, numpy.ndarray.strides, and numpy.ndarray.itemsize.
- ⚠️ While stride tricks give you more control over the resulting NumPy view, the API is not memory-safe — things can get pretty nasty if you miscalculate the itemsize (honestly I think this API should not allow client code to have to deal with item size as I haven’t seen any benefits of exposing this) or the shape or the existing strides, returning data that is actually not the initial array you created, but from a different array altogether which you probably defined few lines back 😱.
- Shoutout to David Chong for reviewing this article.