Python Exercise Lists

# Python Numpy Data Sorting Exercises 3

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)]

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)]

```import numpy as np
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)]

students = np.array(students_marks, dtype=data_type)
print("Initial array:")
print(students)

print("\nSort by marks:")
print(np.sort(students, order='mark'))
```