Is there a way to store NaN in a Numpy array of integers?
I get:
a=np.array([1],dtype=long)
a[0]=np.nan
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: cannot convert float NaN to integer
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, you can’t, at least with current version of NumPy. A
nanis a special value for float arrays only.There are talks about introducing a special bit that would allow non-float arrays to store what in practice would correspond to a
nan, but so far (2012/10), it’s only talks.In the meantime, you may want to consider the
numpy.mapackage: instead of picking an invalid integer like -99999, you could use the specialnumpy.ma.maskedvalue to represent an invalid value.