How to select an element by index from a NumPy array in Python

Selecting an element by index from a NumPy array returns an element at a specified index. For example, selecting the element at row 0 and column 1 from array [[1 2 3] [4 5 6]] returns 2.

Solution for How to select an element by index from a NumPy array in Python : You can use integer array indexing to select an element by index Use the syntax np.array[i,j] to retrieve an element at row index i and column index j from the array.

To retrieve multiple elements, use the syntax np.array[(row_values), (column_values)] where row_values and column_values are a tuple of the same size.

array = np.array([[1, 2, 3], [4, 5, 6]])


how-to-select-an-element-by-index-from-a-numpy-array-in-python