Cristi Constantin wrote:
> Good day.
> I was following this discussion too.
> How about unicode_t ?
> I am trying to make the numpy tutorial you have on Cython Wiki, but 
> instead of np.int_t i need numpy.unicode_ type.
> Do you have any idea how i could do that?
> 
> Check this python code:
> import numpy as np
> a=np.array([0,1,2],np.unicode_)
> print a # array([u'0', u'1', u'2'], dtype='<U1')
> a[0]=u'\u2588'
> a[1]=u'\u00b6'
> a[2]=u'\u2248'
> a.astype('I')
> # UnicodeEncodeError: 'decimal' codec can't encode character u'\u2588' 
> in position 0: invalid decimal Unicode string
> a.astype(np.uint32)
> # Same unicode error.
> 
> What's the best "cast" i can do to have my Unicode Numpy Array?
> Thank you in advance.

This is very badly supported in Cython, mostly because I have no idea 
what usecases people have for such arrays. Would you care to describe 
your usecase?

But if you want to modify Unicode 1-length strings as an integer type, 
you can do (in Cython)

cdef np.ndarray[some_int_type, cast=True] arr = a

Here, some_int_type needs to be an integer of the same size as 
"a.itemsize" would give you above -- I don't know how NumPy stored 
Unicode strings so I actually can't tell you the right one.

-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to