We encounter certain warnings especially while working over nan values. Such warning can often be frustating. But we can handle cautionly.
So this recipe is a short example on how to ignore all numpy warnings.Let's get started.
import numpy as np
Let's pause and look at these imports. Numpy is generally used for working over arrays and performing mathematical operations.
data = np.random.random(1000).reshape(10, 10,10) * np.nan
We have simply setup a random data.
Seterr function comes handy for control of warnings. Here all='ignore' helps in ignoring any type of warnings we might encounter.
np.nanmedian(data, axis=[1, 2])
Above statement bascially triggers a warning. However, because of seterr function, it's being ignored. We will only see output of above code with no warning in final run.
Once we run the above code snippet, we will see:
array([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])