rougier / numpy-100

100 numpy exercises (with solutions)
MIT License
12.17k stars 5.74k forks source link

An alternative solution for Q.19 #188

Closed HenryJi529 closed 2 years ago

HenryJi529 commented 2 years ago
  1. Create a 8x8 matrix and fill it with a checkerboard pattern (★☆☆)

Z = np.zeros((8,8),dtype=int) Z[1::2,::2] = 1 Z[::2,1::2] = 1 print(Z)

An alternative solution will be:

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

Clever. Can you make a PR adding your solution following the existing one? (Make sure to edit the template and not the .md or .ipynd files)

HenryJi529 commented 2 years ago

Sure. Again, thanks for your numpy-100 practice, it really helps me a lot.