ADVERTISEMENT
ADVERTISEMENT

Python program to filter matrix based on a condition

Here, we are going to learn how to filter matrices based on student marks (> 70) in Python?
Submitted by Shivang Yadav, on February 22, 2021

Matrix in python is a two-dimensional data structure which is an array of arrays.

Program to filter matrix based on a condition

T=(("Ajay",90),("Peter",45),("Jack",80))

print("All students : ", T)

R=()

for t in T:
    if(t[1]>=70):
        R+=(t,)

print("Students with score more than 70 : " , R)

Output:

All students :  (('Ajay', 90), ('Peter', 45), ('Jack', 80))
Students with score more than 70 is  (('Ajay', 90), ('Jack', 80))

In the above code, we have created the matrix T, with student name and marks. And then printed the value. The filter is using the greater than sign and store to an array. Then print this matrix.

Python Array Programs »



ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.