I have an array `customers`which holds customer ids, and a `purchases` array which holds the number of purchases of the corresponding customer. I want to create a `tally` array such that the first column holds the customer id and the second column holds the total number of their purchases. Is there a way to create the `tally` array programmatically, i.e. without manually typing *1, 2, 3* for customer id and for the condition in the `np.where` function? I know I could do it with a `for` loop, but I'm looking for a way to avoid it. ```python customers = np.array([3 3 3 2 1 3 1 1 1 1]) purchases = np.array([5 2 8 3 8 3 8 9 9 3]) tally = np.array([ [1, np.sum(purchases[np.where(customers == 1)[0]])], [2, np.sum(purchases[np.where(customers == 2)[0]])], [3, np.sum(purchases[np.where(customers == 3)[0]])], ]) ```
`np.bincount(customers, weights=purchases)` gets you pretty much there