NumPy Internals, Strides, Reshape and Transpose | Paperspace Blog

In the first two parts of our series on NumPy optimization, we have primarily covered how to speed up your code by trying to substitute loops for vectorized code. We covered the basics of vectorization and broadcasting, and then used them to optimize an implementation of the K-Means algorithm, speeding it up by 70x compared to the loop-based implementation.

This is a companion discussion topic for the original entry at
1 Like

Insightful post. I could relate to the np.concatenate problem a lot.
I liked the new way of viewing arrays with branches rather than as cubes. It helps, if we want to understand more dimensional data.

I just came across one small discrepency where I felt you used bits instead of bytes. In the section Numpy Internals in the paragraph ->
In other words, stride for a dimension basically tells you how much blocks of physical memory you must skip in the contiguous memory to reach the next element in that dimension while keeping the others constant. For e.g. consider index [0][2] . In order to jump to next element in the first dimension [1][2] , we must jump 32 bits in memory. Similarly, we jump 8 bits in physical memory to get to index [0][3] .
I believe you meant bytes instead of bits.

Also in the line -> Each integer takes up 32 bits or 8 bytes of memory
I belive you meant 64 bits as the example had int64 as far as I know.

Apart from that, an interesting post.

I believe you mean “contiguous”, not “contagious”, throughout the post.