On Sat, May 8, 2010 at 9:16 PM, Ryan May <rmay31@gmail.com> wrote:
On Sat, May 8, 2010 at 7:52 PM, Gökhan Sever <gokhansever@gmail.com> wrote:
Hello,
Consider my masked arrays:
I[28]: type basic.data['Air_Temp'] -----> type(basic.data['Air_Temp']) O[28]: numpy.ma.core.MaskedArray
I[29]: basic.data['Air_Temp'] O[29]: masked_array(data = [-- -- -- ..., -- -- --], mask = [ True True True ..., True True True], fill_value = 999999.9999)
I[17]: basic.data['Air_Temp'].data = np.ones(len(basic.data['Air_Temp']))*30
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
----> 1 2 3 4 5
AttributeError: can't set attribute
Why this assignment fails? I want to set each element in the original basic.data['Air_Temp'].data to another value. (Because the main instrument was forgotten to turn on for that day, and I am using a secondary measurement data for Air Temperature for my another calculation. However it fails. Although single assignment works:
I[13]: basic.data['Air_Temp'].data[0] = 30
Shouldn't this be working like the regular NumPy arrays do?
Based on the traceback, I'd say it's because you're trying to replace the object pointed to by the .data attribute. Instead, try to just change the bits contained in .data:
basic.data['Air_Temp'].data[:] = np.ones(len(basic.data['Air_Temp']))*30
Ryan
-- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma
Thanks for the pointer Ryan. Now it works as it is supposed to be. -- Gökhan