I am new to Python and Numpy, and I ran into the problem that I cannot change numpy.recarray when applied to masked views. I read recarray from a file, then create two masked views, and then try to change the values in a for loop. Here is a sample code.
import numpy as np
import matplotlib.mlab as mlab
dat = mlab.csv2rec(args[0], delimiter=' ')
m_Obsr = dat.is_observed == 1
m_ZeroScale = dat[m_Obsr].scale_mean < 0.01
for d in dat[m_Obsr][m_ZeroScale]:
d.scale_mean = 1.0
But when I print the result
newFile = args[0] + ".no-zero-scale"
mlab.rec2csv(dat[m_Obsr][m_ZeroScale], newFile, delimiter=' ')
All scale_means in the files are still null.
I have to do something wrong. Is there a correct way to change View values? Is it because I apply two views one after another?
Thank.
source
share