pythonnumpy
Ben Gorman

Ben Gorman

Life's a garden. Dig it.

Given a 1-D array called freckle,

import numpy as np
freckle = np.array([2,7,3,1,0,5])

perform the following sequence of operations.

Step Array
freckle 2, 7, 3, 1, 0, 5
1. Sort the elements in descending order 7, 5, 3, 2, 1, 0
2. Take their cumulative sum 7, 12, 15, 17, 18, 18
3. Undo the sort from step 1 17, 7, 15, 18, 18, 12

Solution

This content is gated

Subscribe to one of the products below to gain access