Using Numeric 24.0b2 with Scientific.IO.NetCDF

Robert Kern rkern at ucsd.edu
Tue Jul 5 21:40:33 CEST 2005


bandw wrote:
> Robert,
> 
> Thanks for your reply.  However, I am still having problems.  Sometimes
> I get a scalar return
> and sometimes I get an array.  For example, using the netCDF file:
> 
> netcdf simple {
>    dimensions:
>            num = 3 ;
>    variables:
>            float temp0(num) ;
>            int   temp1(num) ;
>    data:
> 
>     temp0 = 1., 2., 3. ;
>     temp1 = 1,  2,  3 ;
> }
> 
> and running:
> 
> #
> import Numeric
> print Numeric.__version__
> from Scientific.IO.NetCDF import NetCDFFile
> 
> cdf_file1 = NetCDFFile("simple.nc","r")
> 
> var1 = cdf_file1.variables["temp0"][:]
> var2 = cdf_file1.variables["temp1"][:]
> min1 = reduce(Numeric.minimum,var1)
> min2 = reduce(Numeric.minimum,var2)
> 
> print "Types of var1, min(var1), min1:",type(var1), type(min(var1)),
> type(min1)
> print "Types of var2, min(var2), min2:",type(var2), type(min(var2)),
> type(min2)
> 
> I get:
> 
> 24.0b2
> Types of var1, min(var1), min1: <type 'array'> <type 'array'> <type
> 'array'>
> Types of var2, min(var2), min2: <type 'array'> <type 'int'> <type
> 'int'>
> 
> Even something like:
> 
>>>>import Numeric
>>>>a = Numeric.array([1.,2.])
>>>>print type(a),type(min(a))
> 
> <type 'array'> <type 'float'>
> 
> does not produce an array.

Hmm, odd. Anyways, follow my advice: use minimum.reduce() and wrap 
results in float() or array() if you really need floats or rank-0 arrays.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list