[Numpy-discussion] Bus Error with string in ndarray with named fields

Per B. Sederberg persed at princeton.edu
Fri Apr 20 10:38:34 EDT 2007


>>>

Hi Folks:

I'm getting a very strange bus error in the recent versions of numpy (almost
current svn).  Here's how you can (hopefully) replicate it:

On my MacBook:

Python 2.4.3 (#1, Apr  7 2006, 10:54:33)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import numpy as N
 >>> N.version.version
'1.0.2.dev3569'
 >>> fields = [('x',(N.str,40))]
 >>> dat = N.zeros(1,fields)
 >>> dat
 Bus error


On my linux cluster:

Python 2.4.3 (#1, May  8 2006, 11:36:25)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as N
>>> N.version.version
'1.0.2.dev3567'
>>> fields = [('x',(N.str,40))]
>>> dat = N.zeros(1,fields)
>>> dat
Segmentation fault


But it works on my linux desktop with an older numpy:

Python 2.4.4c1 (#2, Oct 11 2006, 20:00:03)
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as N
>>> N.version.version
'1.0rc1'
>>> fields = [('x',(N.str,40))]
>>> dat = N.zeros(1,fields)
>>> dat
array([('',)],
     dtype=[('x', '|S40')])
>>>


Does anyone have any clue as to how to deal with this?  Is there a better way to
create an ndarray with named fields (recarray)?  My real code has a number of
fields of various types, but I was able to narrow it down to anytime I use a
string type.  For example, this works on the machines where using a string fails:

>>> import numpy as N
>>> fields = [('x',N.bool),('y',N.int32)]
>>> dat = N.zeros(1,fields)
>>> dat
array([(False, 0)],
     dtype=[('x', '|b1'), ('y', '<i4')])
>>>

Thanks for any help,
Per





More information about the NumPy-Discussion mailing list