The following snippet demonstrates a problem in the interaction of numarray 1.5.2 with numpy 1.0.1 (and older versions): ------------------- #!/usr/bin/env python import numarray, numpy na = numarray.array(0.) np = numpy.array(0.) na[...] = np ------------------- the last linec causes the error "TypeError: NA_setFromPythonScalar: bad value type." The problem occured in a perfectly normal piece of code combining PyTables (internally based on numarray) with calculations done in NumPy. AFAICS, it should work but simply is a bug somewhere in numarray or numpy. Thanks, Norbert
On 12/24/06, Norbert Nemec <Norbert.Nemec.list@gmx.de> wrote:
The following snippet demonstrates a problem in the interaction of numarray 1.5.2 with numpy 1.0.1 (and older versions):
------------------- #!/usr/bin/env python
import numarray, numpy
na = numarray.array(0.) np = numpy.array(0.)
na[...] = np -------------------
the last linec causes the error "TypeError: NA_setFromPythonScalar: bad value type."
The problem occured in a perfectly normal piece of code combining PyTables (internally based on numarray) with calculations done in NumPy. AFAICS, it should work but simply is a bug somewhere in numarray or numpy.
Recent versions of PyTables work fine with numpy. Unless you have old tables using the numarray flavor I suggest making the change. It is probably possible to read the numarray data into numpy by specifying a particular flavor in the read statement, but Francesc could probably tell you more about that. Chuck
On 12/24/06, Norbert Nemec <Norbert.Nemec.list@gmx.de> wrote:
The following snippet demonstrates a problem in the interaction of numarray 1.5.2 with numpy 1.0.1 (and older versions):
------------------- #!/usr/bin/env python
import numarray, numpy
na = numarray.array(0.) np = numpy.array(0.)
na[...] = np
As a work around, do In [5]: na[...] = int(np) Chuck
A Diumenge 24 Desembre 2006 13:57, Norbert Nemec escrigué:
The following snippet demonstrates a problem in the interaction of numarray 1.5.2 with numpy 1.0.1 (and older versions):
------------------- #!/usr/bin/env python
import numarray, numpy
na = numarray.array(0.) np = numpy.array(0.)
na[...] = np -------------------
the last linec causes the error "TypeError: NA_setFromPythonScalar: bad value type."
The problem occured in a perfectly normal piece of code combining PyTables (internally based on numarray) with calculations done in NumPy. AFAICS, it should work but simply is a bug somewhere in numarray or numpy.
Well, I'm not sure whether we should take this as a bug of numarray (although numpy is happily accepting rank-0 arrays from numarray or Numeric, so we won't have this problem in forthcoming PyTables 2.0). In any case, here you have a quick workaround for PyTables: Index: tables/Array.py =================================================================== --- tables/Array.py (revision 2166) +++ tables/Array.py (revision 2167) @@ -656,7 +656,10 @@ # Assign the value to it try: - narr[...] = value + if hasattr(value, 'shape') and value.shape == (): # Rank-0 case + narr[...] = value[()] + else: + narr[...] = value except Exception, exc: #XXX raise ValueError, \ """value parameter '%s' cannot be converted into an array object compliant with %s: The above patch will accept rank-0 arrays from both NumPy or Numeric. It has also been applied into std-1.4 branch: http://www.pytables.org/trac/changeset/2168/branches Cheers! --
0,0< Francesc Altet http://www.carabos.com/ V V Cárabos Coop. V. Enjoy Data "-"
participants (3)
-
Charles R Harris
-
Francesc Altet
-
Norbert Nemec