Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Replace all values in a list with np.nan

How to replace all values within a list with np.nan?

a = [1.58, 2.13, 3.98, 4.12]

and what i want is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a = [nan, nan, nan, nan]

I have tried many options like replace or list comprehension, but it didn’t work.

>Solution :

import numpy as np
a = [1,2,3,4]
a = [np.nan]*len(a)
print(a)

Output:

[nan, nan, nan, nan]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading