I separate two numpy arrays:
>>> import numpy as np
>>> a1 = np.array([[ 0, 3],
[ 0, 2]])
>>> a2 = np.array([[ 0, 3],
[ 0, 1]])
>>> d = a1/a2
>>> d
array([[ nan, 1.],
[ nan, 2.]])
>>> where_are_NaNs = np.isnan(d)
>>> d[where_are_NaNs] = 0
>>> d
>>> array([[ 0., 1.],
[ 0., 2.]])
I'm looking for a way to get 0 instead of Nan without using for loops?
Does numpy have a similar function fillna()in pandas?
source
share