Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

Slicing 2-D Arrays

Example

Starting from the second element, slice the elements from index 1 to index 4 (excluding index 4).

import numpy as np

arr = np.array([[12345], [678910]])

print(arr[11:4])
Note: Keep in mind that the second element has an index of 1.

Example

From both elements, retrieve the value at index 2.

import numpy as np

arr = np.array([[12345], [678910]])

print(arr[0:22])

Example

From both elements, slice from index 1 to index 4 (excluding index 4), which will yield a 2-D array.

import numpy as np

arr = np.array([[12345], [678910]])

print(arr[0:21:4])