rougier / numpy-100

100 numpy exercises (with solutions)
MIT License
12.05k stars 5.7k forks source link

Add alternative solution for Q.19 #189

Closed HenryJi529 closed 1 year ago

rougier commented 1 year ago

Thanks

Stefan-Heimersheim commented 1 year ago

Just to double check, doesn't this only work for odd squares? I.e. not for 8x8?

In [82]: arr = np.ones(64,dtype=int)
    ...: arr[::2]=0
    ...: arr = arr.reshape((8,8))
    ...: print(arr)
[[0 1 0 1 0 1 0 1]
 [0 1 0 1 0 1 0 1]
 [0 1 0 1 0 1 0 1]
 [0 1 0 1 0 1 0 1]
 [0 1 0 1 0 1 0 1]
 [0 1 0 1 0 1 0 1]
 [0 1 0 1 0 1 0 1]
 [0 1 0 1 0 1 0 1]]
rougier commented 1 year ago

Oh yes, good point. We should remove this alternative form then. Can you make a PR (or do you see how to fix it?)

Stefan-Heimersheim commented 1 year ago

Sure! I'll make a PR to remove it (can't see a simple or elegant way to make this work)