私はいくつかの測定値からのデータを含む2D配列を持っています。私は良いデータだけを考慮して各列に沿って平均しなければなりません。 したがって、私は、その(i、j)のデータが良いか悪いかを示す1と0を含む同じ形の別の2D配列を持っています。 「悪い」データの中には、ナノデータもあります。Pythonのマスクを使って列を平均してみる
def mean_exc_mask(x, mas): #x is the real data arrray
#mas tells if the data at the location is good/bad
sum_array = np.zeros(len(x[0]))
avg_array = np.zeros(len(x[0]))
items_array = np.zeros(len(x[0]))
for i in range(0, len(x[0])): #We take a specific column first
for j in range(0, len(x)): #And then parse across rows
if mas[j][i]==0: #If the data is good
sum_array[i]= sum_array[i] + x[j][i]
items_array[i]=items_array[i] + 1
if items_array[i]==0: # If none of the data is good for a particular column
avg_array[i] = np.nan
else:
avg_array[i] = float(sum_array[i])/items_array[i]
return avg_array
私はすべての値をナノにしています。
ここで間違っていることや何か別の方法についてのアイデアはありますか?