Better HN
topnewbestaskshowjobs
Log inSign up

fscknumpy

6 karma · joined May 15, 2025 (1y ago) · 1 submissions

Submissions

comment 1y ago · link · parent

I had to make a HN account just to show this numpy "feature".

Create an array like this np.zeros((10, 20, 30)), with shape (10, 20, 30).

Clearly if you ask for array[0][:, [0,1]].shape you will get an output of shape (20, 2), because you first remove the first dimension, and then : broadcasts across the second dimension, and you get the first two elements of the third dimension.

Also, obviously we know that in numpy array[a][b][c] == array[a,b,c]. Therefore, what do you think array[0, :, [0,1]].shape returns? (20, 2)? Nope. (2, 20).

Why? Nobody knows.