Skip to content

Gold Miner Solution


gold[locs[:, 0], locs[:, 1]]
# array([2, 6, 2, 8, 2])

Explanation

To access the gold at the first prospect location, we can do

gold[0, 4]
# 2

To access the gold at all five prospect locations, we can do

i = [0,2,2,5,6]
j = [4,2,3,1,3]
gold[i, j]
# array([2, 6, 2, 8, 2])

To build the i and j index arrays dynamically, we can do

i = locs[:, 0]  # (1)!
j = locs[:, 1]  # (2)!
  1. i represents the first column of locs
  2. j represents the second column of locs

Putting it all together..

gold[locs[:, 0], locs[:, 1]]
# array([2, 6, 2, 8, 2])

See the problem