# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment
responses = initialize_assignment("7_numpy_q", "week_3", "lecture", assignment_points = 5.0, assignment_tag = 'week3-lecture')
# Initialize Otter
import otter
grader = otter.Notebook("7_numpy_q.ipynb")
โ Sorting M&Ms with NumPy#
Instructions:#
Imagine you work at an M&M sorting facility. You receive a batch of M&Ms in random order, and your task is to sort them by size using NumPyโs built-in sorting functionality.
Write a function sort_mm_sizes()
that:
1. Imports NumPy as np
.
2. Takes a NumPy array of integers representing the sizes of M&Ms.
3. Sorts the array in ascending order using NumPyโs np.sort()
method.
4. Returns the sorted array.
...
def sort_mm_sizes(mm_sizes):
# Sort the array using NumPy's built-in method
...
return sorted_sizes
# Example usage
mm_sizes = np.array([3, 1, 4, 1, 5, 9])
sorted_sizes = sort_mm_sizes(mm_sizes)
print("Sorted M&M sizes:", sorted_sizes)
grader.check("numpy-mm-sorting")
Submitting Assignment#
Please run the following block of code using shift + enter
to submit your assignment, you should see your score.
from pykubegrader.submit.submit_assignment import submit_assignment
submit_assignment("week3-lecture", "7_numpy_q")