bug fix: memory error in 32bit system
use np.nonzero to index nan and inf