pypipython-2.795% confidence\u2191 272

sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype('float64')

Full error message
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) == True] = 0

to remove the infinite values but this did not work either. 
What can I do to get rid of the infinite values in my matrix, so that I can use the affinity propagation algorithm?

I am using anaconda and python 2.7.9.

This might happen inside scikit, and it depends on what you're doing. I recommend reading the documentation for the functions you're using. You might be using one which depends e.g. on your matrix being positive definite and not fulfilling that criteria. EDIT: How could I miss that: np.isnan(mat.any()) #and gets False np.isfinite(mat.all()) #and gets True is obviously wrong. Right would be: np.any(np.isnan(mat)) and np.all(np.isfinite(mat)) You want to check whether any of the elements are NaN, and not whether the return value of the any function is a number...

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/15ef65fa40c464770481eb0c7440b71443d2b4a482504c5aabf17de43f808bb8
hash \u00b7 15ef65fa40c464770481eb0c7440b71443d2b4a482504c5aabf17de43f808bb8
sklearn error ValueError: Input contains NaN, infinity or a… — DepScope fix | DepScope