import numpy as np
with np.load("weather_data.npz") as weather:
rain = weather["rain"]
uk_mask = weather["uk"]
irl_mask = weather["ireland"]
spain_mask = weather["spain"]
np.mean(rain)
This is very small since it's in metres, so let's convert it into mm:
rain *= 1000
np.mean(rain)
uk_mask.dtype
uk_mask.shape
This is the same as the rain
array:
rain.shape
What filtering method to use:
[]
will lose the original shape, but since we're averaging the whole thing that doesn't matternp.where
will be tricky as if we fill the masked-out areads with 0
then it will skew the meanmasked_array
would work fineFor questions like this, using []
is often simplest:
uk_rain = rain[uk_mask]
np.mean(uk_rain)
np.mean(rain[irl_mask])
np.mean(rain[spain_mask])
The UK has the heaviest rain, followed by Ireland, followed by Spain.