On May 8, 2010, at 9:51 PM, Gökhan Sever wrote:
On Sat, May 8, 2010 at 9:29 PM, Eric Firing <efiring@hawaii.edu> wrote: On 05/08/2010 04:16 PM, Ryan May wrote:
On Sat, May 8, 2010 at 7:52 PM, Gökhan Sever<gokhansever@gmail.com> wrote:
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
Also, you since you are setting all elements to a single value, you don't need to generate an array on the right-hand side. And, you don't need to manipulate ".data" directly--I think it is best to avoid doing so. Consider:
Yep. The "data" attribute is in fact a read-only property that retuns a view of the masked array as a standard ndarray. If you need to set individual values, just do so on the masked array. If you need to mask a value, use the syntax
yourarray[yourindex] = np.ma.masked