First page Back Continue Last page Overview Graphics
Exercises
- Create a null vector of size 7
>>> np.zeros(7)
array([ 0., 0., 0., 0., 0., 0., 0.])
- Create a 8x8 matrix and fill it with a checkerboard pattern
>>> checkerboard = np.zeros((8,8),dtype=int)
>>> checkerboard[::2,1::2] = 1
>>> checkerboard[1::2,::2] = 1
>>> print(checkerboard)
[[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]]
or
>>> np.tile([[1,0],[0,1]],(4,4))