0

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:

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.

Reut
  • 1,555
  • 4
  • 23
  • 55

1 Answers1

1

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
sehan2
  • 1,700
  • 1
  • 10
  • 23