Iteration means looping through each element of an array. Most commonly for loop is used for iterating through an array.
Iterating
•
Iteration means looping through each element of an array. Most commonly for
loop is used for iterating through an array.
import numpy as np
arr = np.array([10,20,30,40,50])
for x in arr:
print(x)
10
20
30
40
50
Code explanation: In
above code,
There
is a for loop that iterates over
each element in the arr array. For
each element x, it prints the value
to the console,
import numpy as np
arr = np.array([[1,2,3],
[4,5,6],
[7,8,9]])
for row in arr:
print("Row: ",row)
Row: [1 2 3]
Row: [4 5 6]
Row: [7 8 9]
In
above code, the code
for row in arr:
print("Row:
", row)
•
This is a for loop that iterates
over each row of the 2D array.
•
In each iteration, the variable row holds one row of the matrix.
•
It prints each row with the label "Row: ".
Python for Data Science: Chapter 5: NumPy and Pandas Libraries : Tag: Computer Programming, Python, Data Science : Python library - NumPy: Iterating
Python for Data Science
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 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