How to access NumPy Array Indexing
Ask by ICSM Computer
Updated 05 Nov 2025
1. Basic Indexing
Just like Python lists:
2. 2D Array Indexing
Use
[row, column]:You can also access entire rows or columns:
3. Slicing
You can extract a range of elements:
For 2D arrays:
4. Integer (Fancy) Indexing
Use lists or arrays of indices:
For 2D arrays:
Explanation:
(0,1)and(2,0)are the chosen coordinates.5. Boolean Indexing
Select elements that satisfy a condition:
You can also combine conditions:
For 2D arrays:
6. Assigning Values
You can modify elements directly:
Boolean assignment:
7. Using
np.i()for Multi-dimensional SelectionIf you want to select specific rows and columns:
Summary Table
arr[2]arr[1, 2]arr[1:4]arr[[0,2,4]]arr[arr > 5]