[Numpy-discussion] Documenting chararrays

Christopher Hanley chanley@stsci....
Wed Jul 23 09:16:57 CDT 2008


Stéfan van der Walt wrote:
> Hi all,
> 
> Should we document character arrays?  Does anybody still use them?
> 
> I think their behaviour can largely be duplicated by object arrays.
> They also seem to be broken:
> 
>>>> x = np.array(['1', '2', '3', '4']).view(np.chararray)
> 
>>>> x*3
> chararray(['111', '222', '333', '444'],
>       dtype='|S4')
> 
> All good, but:
> 
>>>> x = np.array(['12', '34', '56', '78']).view(np.chararray)
> 
>>>> x * 3
> chararray(['1212', '3434', '5656', '7878'],
>       dtype='|S4')
> 
> Whereas with object arrays:
> 
>>>> np.array(['12', '34', '56', '78'], dtype=object) * 3
> array([121212, 343434, 565656, 787878], dtype=object)
> 
> Similaryly:
> 
>>>> x.rjust(3)
> chararray(['  a', '  b', '  c', '  d'],
>       dtype='|S3')
> 
>>>> x = np.array(['a','b','c','d']).view(np.chararray)
> 
>>>> x.rjust(3)
> chararray(['  a', '  b', '  c', '  d'],
>       dtype='|S3')
> 
> But then
> 
>>>> x = np.array([['ab','cd'], ['ef','gh']]).view(np.chararray)
>>>> x.rjust(5) # BOOM
> 
> Cheers
> Stéfan
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion

I know that chararrays are used by pyfits.

Chris


-- 
Christopher Hanley
Systems Software Engineer
Space Telescope Science Institute
3700 San Martin Drive
Baltimore MD, 21218
(410) 338-4338


More information about the Numpy-discussion mailing list