[SciPy-dev] chararry array method
Christopher Hanley
chanley at stsci.edu
Thu Dec 29 16:46:00 EST 2005
Travis Oliphant wrote:
>
> I'm not sure. Presumably it would pick up its shape from the input object.
>
> At some point, I think I'd like to move the chararray into C and have it
> be the default return object whenever a string or unicode base-type
> array is requested.
>
> You can already have arrays of strings without the chararray, except
> comparisons don't work. There are lots of ways to solve that problem,
> and I'm not sure the chararray is the best way. But, it's functional.
>
> -Travis
>
I guess I'm trying to understand if the following example will work. In
numarray, I can say the following:
In [24]: from numarray import strings as chararray
In [25]: arr2 = chararray.array('abcdefg'*10,itemsize=10)
In [26]: arr2
Out[26]:
CharArray(['abcdefgabc', 'defgabcdef', 'gabcdefgab', 'cdefgabcde',
'fgabcdefga', 'bcdefgabcd', 'efgabcdefg'])
However, when attempting to do something similar with scipy.base I
receive the following:
In [27]: arr = sb.chararray.array('abcdefg'*10,itemlen=10)
---------------------------------------------------------------------------
exceptions.ValueError Traceback (most
recent call last)
/data/sparty1/dev/devCode/<console>
/data/sparty1/dev/site-packages/lib/python/scipy/base/chararray.py in
array(obj, itemlen, copy, unicode, fortran)
322 return chararray(val.shape, itemlen, unicode, buffer=val,
323 strides=val.strides,
--> 324 fortran=fortran)
325
326 def asarray(obj, itemlen=7, unicode=False, fortran=False):
/data/sparty1/dev/site-packages/lib/python/scipy/base/chararray.py in
__new__(subtype, shape, itemlen, unicode, buffer, offset, strides, fortran)
28 buffer=buffer,
29 offset=offset, strides=strides,
---> 30 fortran=fortran)
31 return self
32
ValueError: need to give a valid shape as the first argument
Chris
More information about the SciPy-Dev
mailing list