Fix Python – sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)

I am using sklearn and having a problem with the affinity propagation. I have built an input matrix and I keep getting the following error.
ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’).

I have run
np.isnan(mat.any()) #and gets False
np.isfinite(mat.all()) #and gets True

I tried using
mat[np.isfinite(mat) ==….