Python for Data Science: Chapter 5: NumPy and Pandas Libraries

NumPy: Indexing

Python library

Indexing means selecting specific element from NumPy array using the position of that element. In python index starts from 0.

Indexing

• Indexing means selecting specific element from NumPy array using the position of that element. In python index starts from 0.

Following Python programs illustrate how indexing is used for NumPy array.

 

Python program for indexing one D array

import numpy as np

 arr = np.array([10,20,30,40,50])

print("Element at index 0: ",arr[0])

print("Element at last position: ",arr[‒1])

Output

Element at index 0: 10

Element at last position: 50

 

Python program for indexing two D array

import numpy as np

arr = np.array([[1,2,3],

[4,5,6],

[7,8,9]])

print(arr[0,2])

print(arr[2,1])

Output

3

8

Code explanation: In above code,

Using first print statement, we can access the element 3 which is at position 0th row and 2nd  column.

Using second print statement, we can access element 8 which is at position at position 2nd row and first column.

 

Python for Data Science: Chapter 5: NumPy and Pandas Libraries : Tag: Computer Programming, Python, Data Science : Python library - NumPy: Indexing


Python for Data Science: Chapter 5: NumPy and Pandas Libraries



Under Subject


Python for Data Science

AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation



Related Subjects


English Essentials II

EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation



Linear Algebra

MA25C02 2nd Semester | 2025 Regulation


Applied Physics (CSIE) II

PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Digital Principles and Computer Organization

CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electrical and Electronics Engineering

EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Python for Data Science

AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Re-Engineering for Innovation

ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Python for Data Science - Laboratory

AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation