Skip to content

Big Fish Problem


10 fish occupy a 5x5x5 grid of water 🐟. Each fish decides to move to a new (i,j,k) location given by the 2-d array below. If multiple fish end up occupying the same cell, the biggest fish eats the smaller fish. Determine which fish survive.

import numpy as np

locs = np.array([
    [0,0,0],
    [1,1,2],
    [0,0,0],
    [2,1,3],
    [5,5,4],
    [5,0,0],
    [5,0,0],
    [0,0,0],
    [2,1,3],
    [1,3,1]
])

generator = np.random.default_rng(1010)
weights = generator.normal(size=10)

print(weights)
# [-1.699  0.538 -0.226 -1.09   0.554 -1.501  0.445  1.345 -1.124  0.212]
How to print fewer decimal places

Use np.set_printoptions(precision=3) to show values with just three decimal places.


Try with Google Colab