[Numpy-discussion] Padding policy in CharArrays

Francesc Altet faltet at carabos.com
Mon Jan 3 13:26:27 CST 2005


A Dilluns 03 Gener 2005 17:40, Todd Miller va escriure:
> >>> a=strings.array(None, itemsize = 4, shape=1, kind=strings.RawCharArray)
> >>> a[0] = '0\0\0\0'
> >>> print repr(a >= '0\x00\x00\x00\x01')
> array([0], type=Bool)  
> 
> You'll note that I "hand padded" the assigned value;   because
> RawCharArray is a little used feature,  it needs more work.  I think
> RawCharArray either makes partial/inconsistent use of NULL padding.

Well, I've already tried that, but what I would like is to have the
possibility to assign values *and* padding with NULL values. However, using
a RawCharArray does not allow this:

>>> a=strings.array(None, itemsize = 4, shape=1, kind=strings.RawCharArray)
>>> a
RawCharArray(['    '])
>>> a[0] = str(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.4/site-packages/numarray/strings.py", line 185, in _setitem
    where[bo:bo+self._itemsize] = self.pad(value)[0:self._itemsize]
TypeError: right operand length must match slice length

> Give RawCharArray a try;  it *is* the basis of CharArray, so it
> basically works but there will likely be a few issues to sort out.  My
> guess is that anything that really needs fixing can be added for
> numarray-1.2.

Mmm, perhaps having the possibility to select the pad value in CharArray
creation time would be nice.

Cheers,

-- 
Francesc Altet     >qo<   http://www.carabos.com/
Cárabos Coop. V.   V  V   Enjoy Data
                    ""





More information about the Numpy-discussion mailing list