[Numpy-discussion] Re: take for character arrays?

Todd Miller jmiller at stsci.edu
Thu Apr 15 12:56:01 CDT 2004


On Thu, 2004-04-15 at 13:06, Faheem Mitha wrote:
> On Thu, 15 Apr 2004 05:13:29 +0000 (UTC), Faheem Mitha
> <faheem at email.unc.edu> wrote:
> 
> > Hi,
> >
> > I'm trying to extract subarrays of a character array using take(), but
> > getting mysterious errors, for example:
> >
> > ValueError: Invalid destination array: partial indices require
> > contiguous non-byteswapped destination
> >
> > I am thinking that perhaps this operation is not supported for
> > character arrays, and I should convert my character array to a numeric
> > array instead (the strings are all of length 1).

This is a bug.  I logged it on source forge.

> 
> I read this again and realised this does not give any specific
> information, and is not very coherent. Got to avoid those late night
> postings. So here are the details. If I set axis = 0 there is no
> problem. I also don't have this problem with numerical arrays.
> 
> I am sure there is a simple reason for this, and hopefully a simple
> workaround.

Try this for a workaround:

s.swapaxes(0,1)
s = s.copy()
r = numarray.take(s, (1,2))
r.swapaxes(0,1)

Regards,
Todd

-- 
Todd Miller <jmiller at stsci.edu>





More information about the Numpy-discussion mailing list