Please let me know if anyone knows of a better way to do about the following. I am trying to replace some values in numpy array. Replace condition is differ in each columns. Suppose I have a numpy array and list of nodata values like:
import numpy as np
array = np.array([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[10,11,12]])
nodata_values = [4, 8, 3]
and what I want to have is array which values are replaced like
array([[ 1., 2., nan],
[nan, 5., 6.],
[ 7., nan, 9.],
[10., 11., 12.]])
I know I can do this:
np.array([np.where(i == nodata_values[idx], np.nan, i)
for idx, i in enumerate(array.T)]).T
But this code using for loop inside therefore applying it to a table with tens of thousands of rows will takes time.