Numpy integer nan

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 Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you … Read more

How to extract an arbitrary line of values from a numpy array?

I have a numpy array that contains some image data. I would like to plot the ‘profile’ of a transect drawn across the image. The simplest case is a profile running parallel to the edge of the image, so if the image array is imdat, then the profile at a selected point (r,c) is simply imdat[r] (horizontal) or imdat[:,c] (vertical).