I am having a problem using Numeric-24.0b2 in conjunction with
the NetCDF module from ScientificPytho n (version 2.4.9).
This problem does not surface using Numeric-23.8. The problem
arises in using the "min" function on a NetCDF floating array.
In 23.8, the "min" function returns a floating scalar, while in
24.0b2 it returns an *array* of length "1". Below I list a
simple NetCDF file and a Python script that illustrate the
problem. When I run the script using 23.8, I get the result:
1.0 <type 'float'>
whereas using 24.0b2 I get:
1.0 <type 'array'>
This creates a backward incompatibility that breaks several of
my codes.
NetCDF file simple.cdl (used to create simple.nc with "ncgen")
--------------------------------------------------------------
netcdf simple {
dimensions:
num = 3 ;
variables:
float temp(num) ;
data:
temp = 1, 2, 3 ;
}
Python script
-------------
import Numeric
from Scientific.IO.N etCDF import NetCDFFile
cdf_file1 = NetCDFFile("sim ple.nc","r")
temp = cdf_file1.varia bles["temp"][:]
print min(temp), type(min(temp)) 5 2357
bandw wrote: I am having a problem using Numeric-24.0b2 in conjunction with the NetCDF module from ScientificPytho n (version 2.4.9). This problem does not surface using Numeric-23.8. The problem arises in using the "min" function on a NetCDF floating array. In 23.8, the "min" function returns a floating scalar, while in 24.0b2 it returns an *array* of length "1". Below I list a simple NetCDF file and a Python script that illustrate the problem. When I run the script using 23.8, I get the result:
1.0 <type 'float'>
whereas using 24.0b2 I get:
1.0 <type 'array'>
This creates a backward incompatibility that breaks several of my codes.
Call float(temp) if you really need a Python float. The change was
intentional such that A[i] would always be an array regardless of the
shape of A. This greatly simplifies certain types of code although the
change does have its transition costs for some specific pieces of older
code like yours.
BTW, you don't want to use the builtin min(). That iterates over the
array as if it were a Python list. Use minimum.reduce( ).
--
Robert Kern rk***@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
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.__versi on__
from Scientific.IO.N etCDF import NetCDFFile
cdf_file1 = NetCDFFile("sim ple.nc","r")
var1 = cdf_file1.varia bles["temp0"][:]
var2 = cdf_file1.varia bles["temp1"][:]
min1 = reduce(Numeric. minimum,var1)
min2 = reduce(Numeric. minimum,var2)
print "Types of var1, min(var1), min1:",type(var 1), type(min(var1)) ,
type(min1)
print "Types of var2, min(var2), min2:",type(var 2), 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(mi n(a))
<type 'array'> <type 'float'>
does not produce an array.
Any comments woud be appreciated.
Fred Clare
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.__versi on__ from Scientific.IO.N etCDF import NetCDFFile
cdf_file1 = NetCDFFile("sim ple.nc","r")
var1 = cdf_file1.varia bles["temp0"][:] var2 = cdf_file1.varia bles["temp1"][:] min1 = reduce(Numeric. minimum,var1) min2 = reduce(Numeric. minimum,var2)
print "Types of var1, min(var1), min1:",type(var 1), type(min(var1)) , type(min1) print "Types of var2, min(var2), min2:",type(var 2), 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(mi n(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 rk***@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Thanks again. I will take your advice. My concern is in not knowing
where in all
my python code I am assuming a scalar return in certain circumstances.
But I
guess I can take care of the errors as they come up.
Fred
I am having more problems with 24.0b2. Consider the NetCDF file:
netcdf very_simple {
dimensions:
num = 2 ;
variables:
float T(num) ;
T:mv = 5.0f ;
data:
T = 1., 2. ;
}
and the python script:
import Numeric
from Scientific.IO.N etCDF import NetCDFFile
file = NetCDFFile("sim ple.nc","r")
T = file.variables["T"]
a = T.mv
print "T.mv = ", a
print "type(T.mv) = ", type(a)
print "len(T.mv) = ", len(a)
print "T.mv[0] = ", a[0]
print "len(T.mv[0]) = ", len(a[0])
print "type(T.mv[0]) = ", type(a[0])
which produces the output:
T.mv = [ 5.]
type(T.mv) = <type 'array'>
len(T.mv) = 1
T.mv[0] = 5.0
len(T.mv[0]) = 1
type(T.mv[0]) = <type 'array'>
I can see no reason why T.mv[0] should be typed as an array. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kyler Laird |
last post by:
Python 2.3.3 (#2, Jan 4 2004, 12:24:16)
on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Numeric
>>> import MLab
>>> import Scientific.Statistics
>>> MLab.std(Numeric.array(, Numeric.Int0))
0.0
>>> MLab.std(Numeric.array(, Numeric.UnsignedInt8))
181.01933598375618
|
by: Gaubitzer Erwin |
last post by:
Hi there
I wrote a short program which reads scientific data from
a file and stores its values in a Numeric array.
At the same time it reads the names of its dimensions which
are then in the same order as the indices of the Numeric
array.
After then I want to access the data in the array by its name
the way that I keep all indices at constant values except the
|
by: skilpat |
last post by:
I am going to be doing a lot of work with large data sets stored in
various netCDF files, and after checking out the alternatives, I would
really like to go with SciPy. The problem is that SciPy offers no
native netCDF support. I have checked out pycdf at
http://pysclint.sourceforge.net/pycdf/, but it requires Numerical
Python. Is there any way to get this working with SciPy without
installing more modules? The less my sysadmin has to...
|
by: jelle |
last post by:
#No rant intended
I'm not at all confused wether I should learn an one of the advanced
array modules, I'm slightly confused over which I should pick up. I'm
impressed with the efforts of SciPy and Scientific, but since I'm
fairly new to programming & OO, choosing Numarray over Numeric hasnt
been that satisfactory at all, which is not a problem of the quality of
Numarray, but the fact that a lot of modules still heavily realy on
Numeric....
|
by: Pieter |
last post by:
Hi,
I'm having some troubles with my numeric-types in my VB.NET 2005
application, together with a SQL Server 2000.
- I first used Single in my application, and Decimal in my database. But a
Single with value 4.475 was converted to a Decimal with value
4.4749999999999996D. So after inserting and selecting it from the database I
got another value than the original!
| |
by: lars.uffmann |
last post by:
Hi - since my Suse 10.1 didn't have netcdf support enabled by default,
I downloaded the sources from
http://www.unidata.ucar.edu/software/netcdf/ then did
../configure --prefix=/usr
make
make test --succeeded
make extra_test --succeeded
make install
In my /usr/include I now have the files
|
by: Jerry |
last post by:
I am writing text out to a text file and I want to LEFT justify the text.
I wave found examples for the following:
// Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers");
Console.WriteLine(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
|
by: vorticitywolfe |
last post by:
Hello,
I am working with a netcdf file and trying to remove a long string
from it e.g.
"KAST BLAH BLAH BLAH BLAH DATA BLAH DATA BLAH BLAH BLAH BLAH BLAH DATA
BLAH DATA BLAH"
Right now what I have works, but takes a long time to run... I think
this could be cut down to a quick 2 second run, but now takes around 5
minutes primarily because of the problem described below...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |