Hands-on: Array slicing
In this exercise we explore the slicing syntax of NumPy arrays.
Source code for this exercise is located in
First, create a 4x4 array with arbitrary values, then
- Extract every element from the second row.
- Extract every element from the third column.
- Assign a value of 0.21 to upper left 2x2 subarray.
Next, create a 8x8 array with chequerboard pattern, i.e. alternating zeros and ones:
1 0 1 ... 0 1 0 ... 1 0 1 ... ...
How many statements you do need for creating the pattern?
© CSC - IT Center for Science Ltd.