rain_locations = np.array ([
[2,3],
[0,1],
[2,2],
[2,3],
[1,1],
[2,3],
[1,1]
])
rain_amounts =
np.array([0.5,1.1,0.2,0.9,1.3,0.4,2.0])
import numpy as np
rain_locations = np.array([
[2, 3],
[0, 1],
[2, 2],
[2, 3],
[1, 1],
[2, 3],
[1, 1]
])
rain_amounts = np.array([0.5, 1.1, 0.2, 0.9, 1.3, 0.4, 2.0])
rainfall_grid = np.zeros((3, 4))
for i in range(rain_locations.shape[0]):
x, y = rain_locations[i]
rainfall_grid[x, y] += rain_amounts[i] print(rainfall_grid)
import numpy as np
def cumulative_rainfall(rain_locations, rain_amounts):
rainfall_grid = np.zeros((3, 4))
for location, amount in zip(rain_locations, rain_amounts):
row, col = location
rainfall_grid[row, col] += amount
return rainfall_grid
rain_locations = np.array([
[2,3],
[0,1],
[2,2],
[2,3],
[1,1],
[2,3],
[1,1]
])
rain_amounts = np.array([0.5,1.1,0.2,0.9,1.3,0.4,2.0])
result = cumulative_rainfall(rain_locations,
rain_amounts)
print(result)
[[0. 1.1 0. 0. ]
[0. 3.3 0. 0. ]
[0. 0. 0.2 1.8]]