Re:Re: [pyngl-talk] Array assignment issue

From: linzhenhua <linzhenhua_at_nyahnyahspammersnyahnyah>
Date: Thu, 11 Sep 2008 07:48:53 +0800 (CST)

  Hi,I have had similiar problem. Try the following trick.

var_NC[:,:]= list(foo[:,:])
 
 
 

--
 
2008-09-11"David Brown" <dbrown_at_ucar.edu> д
Hi Zach,
Your 'foo' variable is created using the default NumPy float type,  float64, which is a 'double' in NetCDF and
PyNIO. On the other hand you create 'var_NC' as type 'f' which is a NetCDF 'float', equivalent to float32 
in NumPy. Make the var_NC type 'd', or make foo into a float32. 
There seems to be some type conversion going on when single elements are assigned. I am not quite sure what
is up with that.  I think the loop code in the script should not work either. I will investigate.
 -dave
On Sep 10, 2008, at 3:47 PM, Zach DuFran wrote:
I am trying to assign values from a 2-d array of floats to a netcdf variable of the same dimensions and dimension size.  Whenever I try to do the assignment in one line, I get the following error:
NIOError: type or dimensional mismatch writing to variable (foo_bar)
Traceback (most recent call last):
  File "reassign.py, line 33, in <module>
    var_NC[:,:] = foo[:,:]
SystemError: error return without exception set
 
However, if I assign the data inside 2 loops, it works (albeit very slowly for large arrays).  The attached script illustrates the problem, as well as the alternative method which works.  Why wont the quicker method of one line assignment work?
 
I am running Python v. 2.5.2 and PyNgl v. 1.2.0 on Linux i686.
 
Thanks for the help-
Zach DuFran
<reassign.py>
_______________________________________________
pyngl-talk mailing list
pyngl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk

_______________________________________________
pyngl-talk mailing list
pyngl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Wed Sep 10 2008 - 17:48:53 MDT

This archive was generated by hypermail 2.2.0 : Wed Oct 01 2008 - 09:47:33 MDT