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

invalid literal for int() with base 10: 'nan' when trying to replace 0 in NaN

I have nd-array with 7 dimensions. I want to change in each band the 0 value into None value (nan).

I have tried to this it like this:

band[band == 0] = "nan"

but then I got the error message:

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

ValueError: invalid literal for int() with base 10: ‘nan’

I have tried to change the nan to None and also np.nan but for the none I have got following error:

TypeError: int() argument must be a string, a bytes-like object or a
number, not ‘NoneType’

and for np.nan:

ValueError: cannot convert float NaN to integer

The array values type is numpy.int64 .

My endgoal here is to be able to change the 0 values into nan values for the array.

>Solution :

You have to change your array data type to float. Here is an example:

import numpy as np
a = np.array([0,1,2,3],dtype=float)
a[a==0] = np.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