In my real problem, I have hundreds of data arrays and result arrays, so I cannot do it manually.
import numpy as np
data1 = np.array([1,2,np.nan,4,5,6,7],dtype=float)
data2 = np.array([11,np.nan,9,4,5,6,71],dtype=float)
data3 = np.array([17,np.nan,13,4,15,6,17],dtype=float)
my_groups = ['result1', 'result2', 'result3']
result1 = data1/data2
result2 = data1/data3
result3 = data3/data2
For every result, I want to convert the np.nan values to -9.0: The longest way of writing is:
result1 = np.where(np.isnan(result1),-9.0,result1)
result2 = np.where(np.isnan(result2),-9.0,result2)
result3 = np.where(np.isnan(result3),-9.0,result3)
But, I want to shorten the script. What is the good way of doing it?
for i in my_groups:
out[i] = np.where(np.isnan(i),-9.0,i)
Of course my code is wrong. Waiting for your ideas.