[Numpy-discussion] Automatic string length in recarray

Thomas Robitaille thomas.robitaille at gmail.com
Wed Nov 4 11:35:25 EST 2009

Pierre GM-2 wrote:
> As a workwaround, perhaps you could use np.object instead of np.str  
> while defining your array. You can then get the maximum string length  
> by looping, as David suggested, and then use .astype to transform your  
> array...

I tried this:


but I get a TypeError:

TypeError                                 Traceback (most recent call last)

/Users/tom/<ipython console> in <module>()

/Users/tom/Library/Python/2.6/site-packages/numpy/core/records.pyc in
fromrecords(recList, dtype, shape, formats, names, titles, aligned,
    625     res = retval.view(recarray)
--> 627     res.dtype = sb.dtype((record, res.dtype))
    628     return res

/Users/tom/Library/Python/2.6/site-packages/numpy/core/records.pyc in
__setattr__(self, attr, val)
    432             if attr not in fielddict:
    433                 exctype, value = sys.exc_info()[:2]
--> 434                 raise exctype, value
    435         else:
    436             fielddict =
ndarray.__getattribute__(self,'dtype').fields or {}

TypeError: Cannot change data-type for object array.

Is this a bug?


View this message in context: http://old.nabble.com/Automatic-string-length-in-recarray-tp26174810p26199762.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.

More information about the NumPy-Discussion mailing list