[Numpy-discussion] Padding policy in CharArrays

Francesc Altet faltet at carabos.com
Thu Jan 6 13:17:05 CST 2005

A Dilluns 03 Gener 2005 22:25, Francesc Altet va escriure:
> Mmm, perhaps having the possibility to select the pad value in CharArray
> creation time would be nice.

I've ended making an implementation of this in numarray. With the patches
(against numarray 1.1.1) I'm attaching, the next works:

>>> b=strings.array(['0'], itemsize = 4, padc="\x00")
>>> b.raw()
>>> b.raw() >= '0\x00\x00\x00\x01'
array([0], type=Bool)

While the actual behaviour in numarray 1.1.1 is:

>>> b=strings.array(['0'], itemsize = 4)
>>> b.raw()
RawCharArray(['0   '])
>>> b.raw() >= '0\x00\x00\x00\x01'
array([1], type=Bool)

As you may have already noted, I've added a new parameter named padc to the
CharArray/RawCharArray constructor being the default pad character value the
space (" "), for backward compatibility. All the current tests for CharArray
passes with patch applied.

The new functionality is restricted to what I needed, but I guess it should
be easily extended to be completely consistent in other cases. Feel free to
add the patch to numarray if you feel it to be appropriate.


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: _chararraymodule.c.patch
Type: text/x-diff
Size: 1085 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20050106/5af42a7e/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strings.py.patch
Type: text/x-diff
Size: 7664 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20050106/5af42a7e/attachment-0001.bin 

More information about the Numpy-discussion mailing list