python - How to modify a NumPy.recarray using its two views -


I am new to Python and Nampi, and I am facing a problem, that I have a numpy.recarray Can not modify, when applying for masked scenes I read recursively from a file, then create two masked sequences, then try to modify the values ​​for the loop. Here is an example code. Import NMP import as matlotlib.mlab as mlab dat = mlab.csv2rec as import (args [0], delimiter = '') m_Obsr = dat.is_observed == 1

  import M_ZeroScale = dat [m_Obsr] .scale_mean & lt; 0.01: d.scale_mean = 1.0  

for Dat [m_Obsr] [m_ZerScale] but when I print the result

  newFile = args [0] + "Zero-zero-level" mlab.rec2csv (dat [m_Obsr] [m_ZeroScale], newFile, delimiter = '')  

All the scale_men in the file are still zero.

Should I Do Something Wrong What is the proper way to modify the values ​​of seeing? Is it because I am implementing two ideas at once?

Thank you.

I think you have a misconception in this period "masked thoughts" and your understanding To be clear (re-free) should be read.

I am quoting from Section 3.4.2:

When the object is selected obj, a non-tubal sequence object, a ndarray (data type integer or bool), or less At least one sequence object or ndarray (with data) is a tupe, advanced selection is starting type integer or boole). There are two types of advanced indexing: Integer and Boolean advanced selection always gives a copy of the data (which gives the view that is opposite to basic slicing).

What you are doing here is the advanced selection (Boolean type) so that you do not have to get a copy and bind it anywhere - you make your changes on the copy and then run it Let's go, then write a new copy from the original.

Once you understand the problem, be simple: make your copy once, make your change on that copy, and write the same copy. I.e .:

  dat = mlab.csv2rec (args [0], delimiter = '') m_Obsr = dat.is_observed == 1 m_ZeroScale = dat [m_Obsr] .scale_mean & lt; 0.01 the_copy = dat [m_Obsr] [m_ZeroScale] The_copy for d: d.scale_mean = 1.0 newFile = args [0] + ".no-zero-scale" mlab.rec2csv (the_copy, newFile, delimiter = '')  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -