December 2017
Intermediate to advanced
386 pages
10h 42m
English
A slice allows for the selection of items from an array from equally spaced rows or columns. If a more general subarray is required, we can use lists as indices. This is illustrated with the following code:
y = x[[2, 3, 1], [0, 3, 5]]
This will assign array([20, 33, 15]) to the array y. The code behaves as if the lists [2, 3, 1] and [0,3,5] are zipped into the sequence of indices (2,0), (3,3), and (1,5). Also notice that the resulting array y is one-dimensional.
Combined with slices, list indexes provides a powerful way to extract items from an array. The following example demonstrates how to select a subset of the columns of an array:
y = x[:, [5, 2, -1]]dumpArray(y)
This code has the effect of selecting ...
Read now
Unlock full access