Skip main navigation

Get 30% off one whole year of Unlimited learning. Subscribe for just £249.99 £174.99. T&Cs apply

Hands-on: Array slicing

Explore the slicing syntax of NumPy arrays
In this exercise we explore the slicing syntax of NumPy arrays.

Source code for this exercise is located in numpy/array-slicing/

First, create a 4×4 array with arbitrary values, then

  1. Extract every element from the second row.
  2. Extract every element from the third column.
  3. Assign a value of 0.21 to upper left 2×2 subarray.

Next, create a 8×8 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.
This article is from the free online

Python in High Performance Computing

Created by
FutureLearn - Learning For Life