1. Write a Python Numpy program to sort the marks of a student according to the course and its marks in increasing order.
The output is:
course = ['Python', 'Machine Learning', 'R Programming', 'Data Science', 'Big Data']
course_mark = [67., 77., 87., 91., 68.]
Expected Answer:
Sorted indices:
[0 4 1 2 3]
Sorted course:
Python 67.0
Big Data 68.0
Machine Learning 77.0
R Programming 87.0
Data Science 91.0
2. Write a Python Numpy program to sort the given array along with the first axis, last axis and flattened array.
The output is:
a = [20,80],[60,40]
Expected Answer:
Initial array:
[[20 80]
[60 40]]
Sort the array along the first axis:
[[20 40]
[60 80]]
Sort the array along the last axis:
[[20 80]
[40 60]]
Sort the flattened array:
[20 40 60 80]
3. Write a Python Numpy program to generate a structured array with the given details in the following output and sort the marks in increasing order.
The output is:
data_type = [('name', 'S20'), ('course', 'S20'), ('mark', float)]
students_marks = [('Mark', 'Python', 68.5), ('Nicole', 'Python', 86.5),('Iven', 'Machine Learning', 68.0), ('Alvin', 'Machine Learning', 80.5)]
Expected Answer:
Initial array:
[(b'Mark', b'Python', 68.5) (b'Nicole', b'Python', 86.5)
(b'Iven', b'Machine Learning', 68. ) (b'Alvin', b'Machine Learning', 80.5)]
Sort by marks:
[(b'Iven', b'Machine Learning', 68. ) (b'Mark', b'Python', 68.5)
(b'Alvin', b'Machine Learning', 80.5) (b'Nicole', b'Python', 86.5)]
4. Write a Python Numpy program to generate a structured array with the given details in the following output and sort the marks in increasing order with the same course.
The output is:
data_type = [('name', 'S20'), ('course', 'S20'), ('mark', float)]
students_marks = [('Mark', 'Python', 68.5), ('Nicole', 'Python', 86.5),('Iven', 'Machine Learning', 68.0), ('Alvin', 'Machine Learning', 80.5)]
Expected Answer:
Initial array:
[(b'Mark', b'Python', 68.5) (b'Nicole', b'Python', 86.5)
(b'Iven', b'Machine Learning', 68. ) (b'Alvin', b'Machine Learning', 80.5)]
Sort by marks:
[(b'Iven', b'Machine Learning', 68. ) (b'Alvin', b'Machine Learning', 80.5)
(b'Mark', b'Python', 68.5) (b'Nicole', b'Python', 86.5)]
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)