Indexing and slicing a NumPy array

Question Q6.1.5

A $3\times 4 \times 4$ array is created with:

In [x]: a = np.linspace(1,48,48).reshape(3,4,4)

Index or slice this array to obtain the following

(a)

20.0

(b)

[  9.  10.  11.  12.]

(c) The $4 \times 4$ array:

   [[ 33.  34.  35.  36.]
    [ 37.  38.  39.  40.]
    [ 41.  42.  43.  44.]
    [ 45.  46.  47.  48.]]

(d) The $3 \times 2$ array:

[[  5.,   6.],
 [ 21.,  22.],
 [ 37.,  38.]]

(e) The $4 \times 2$ array:

[[ 36.  35.]
 [ 40.  39.]
 [ 44.  43.]
 [ 48.  47.]]

(f) The $3 \times 4$ array:

[[ 13.   9.   5.   1.]
 [ 29.  25.  21.  17.]
 [ 45.  41.  37.  33.]]

(g) (Harder) Using an array of indexes, the $2 \times 2$ array:

[[  1.   4.]
 [ 45.  48.]]

Solution

To access solutions, please obtain an access code from Cambridge University Press at the Lecturer Resources page for my book (registration required) and then sign up to scipython.com providing this code.