NumPy Slicing

Slicing is the reading and changing multiple values in an array. It is similar to indexing, however indexing is reading and changing of a single value.

Slicing between two positions in array

The above code will output this result

[ 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39]
[3 5 7 9]

Slicing first and last positions in array

The above code will output this result

[1 3 5]

Slicing last positions in array

The above code will output this result

[35 37 39]

Slicing  two dimensional array

The above code will output this result

[[1 2 3]
[4 5 6]]

[[1 2 3]
[4 5 6]]

array([[2, 3],
[5, 6]])