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

Todd Miller jmiller at stsci.edu
Thu Apr 15 14:58:25 CDT 2004


On Thu, 2004-04-15 at 16:40, Faheem Mitha wrote:
> On Thu, 15 Apr 2004, Todd Miller wrote:
> 
> > On Thu, 2004-04-15 at 16:17, Faheem Mitha wrote:
> > > On Thu, 15 Apr 2004, Todd Miller wrote:
> > >
> > > > Try this for a workaround:
> > > >
> > > > s.swapaxes(0,1)
> > > > s = s.copy()
> > > > r = numarray.take(s, (1,2))
> > > > r.swapaxes(0,1)
> > >
> > > I was trying
> > >
> > > In [50]: ts = numarray.transpose(s)
> > >
> > > In [51]: numarray.take(ts,(1,2),axis=0)
> > > ...
> > > ValueError: Invalid destination array: partial indices require
> > > contiguous non-byteswapped destination
> > >
> > > In [52]: tscopy = numarray.transpose(s).copy()
> > >
> > > In [53]: numarray.take(tscopy,(1,2),axis=0)
> > > Out[53]:
> > > CharArray([['b', 'e', 'h'],
> > >            ['c', 'f', 'i']])
> > >
> > > Is this the same or a related bug?
> >
> > Same bug.  Making a copy of the transposed array ensures that it (the
> > copy) is contiguous.
> 
> I am wondering if this bug affects boost-python as well. I got the same
> behaviour when using boost.python's version of take.

The bug shouldn't affect numerical arrays because there are different
underlying implementations of take.

> Can you point to where in the source code the bug is? Thanks.

I think the relevant modules are numarray.generic and numarray.ufunc. 
There's a support function which computes the shape of the take() result
in generic.py, _takeShape().  It's testing for a property,
contiguousness, which is not required by the generic take code but is
required by the numerical code.  

The fix may be to factor the exception out of _takeShape and put it into
the (numerical) ufunc.put() setup code somewhere. 

Regards,
Todd

-- 
Todd Miller <jmiller at stsci.edu>





More information about the Numpy-discussion mailing list