[SciPy-dev] 'nuther Q re: chararray

josef.pktd at gmail.com josef.pktd at gmail.com
Tue Aug 11 19:36:10 EDT 2009


On Tue, Aug 11, 2009 at 7:30 PM, <d_l_goldsmith at yahoo.com> wrote:
> >From "Guide to Numpy":
>
> "Perhaps the easiest way to create a chararray is to use self.view(chararray) where self is an ndarray of string or unicode data-type."
>
> OK, but what is "(chararray)"?  In particular, my best guesses yielded:
>
>>>> c = np.empty((2,2), dtype=unicode)
>>>> c
> array([[u'\u0f01\ude68', u'\uf880\udc00'],
>        [u'\uf0c0\udc00', u'\u5300']],
>       dtype='<U1')
>>>> c.view(chararray) # can't mean it literally, right?
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'chararray' is not defined
>>>> c.view(C) # does the expression assign a value to the argument?
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'C' is not defined
>>>> C = np.chararray((2,2)) # this is most logical
>>>> c.view(C)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ValueError: Dtype must be a numpy data-type
>
> So, what does Travis mean?  Thanks,
>
> DG
>
>

with this type of error I usually check the namespace

>>> import numpy as np
>>> np.chararray
<class 'numpy.core.defchararray.chararray'>
>>> c = np.empty((2,2), dtype=unicode)
>>> c.view(np.chararray)
chararray([['', u'\x04'],
       [u'\x01', u'\uf3db\ude20']],
      dtype='<U1')

But I have no idea what chararrays are

Josef

>
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>



More information about the SciPy-Dev mailing list