Skip to content

Instantly share code, notes, and snippets.

@c0ldlimit
Last active September 5, 2022 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c0ldlimit/4287824 to your computer and use it in GitHub Desktop.
Save c0ldlimit/4287824 to your computer and use it in GitHub Desktop.
Converting None to NaN in numpy when casting a list to numpy arrays #numpy #c0ldlimit #python
import numpy as np
x = array([3,4,None,55])
y = np.array(x,dtype=float)
# OR
y = np.array(x)
z = y.astype(float)
@sremm
Copy link

sremm commented Mar 8, 2021

Thanks, this was just what i was looking for ;)

@ernstklrb
Copy link

I got here while looking for the reverse operation. It can be done like this: u = np.where(np.isnan(y), None, y).tolist()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment