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

Faheem Mitha faheem at email.unc.edu
Thu Apr 15 10:07:15 EDT 2004


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).

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.

Thanks in advance.

                                                          Faheem.

**************************************************************************
In [22]: import numarray.strings as str

In [23]: import numarray

In [24]: s = str.array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i'],shape=(3,3))

In [25]: numarray.take(s,(1,2),axis=1)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call
last)

/home/faheem/wc/corrmodel/boost/<console>

/usr/lib/python2.3/site-packages/numarray/ufunc.py in take(array,
indices, axis, outarr, clipmode)
   1779             raise ValueError("indices must be a sequence")
   1780         work = _gen.swapaxes(array, 0, axis)
-> 1781         work = work._take((indices,), outarr=outarr,
clipmode=clipmode)
   1782         return _gen.swapaxes(work, 0, axis)
   1783     else:

/usr/lib/python2.3/site-packages/numarray/generic.py in _take(self,
indices, **keywds)
    795     def _take(self, indices, **keywds):
    796         indices = list(indices)
--> 797         impliedShape, N = _takeShape(self, indices)
    798         result = self._clone(shape=impliedShape)
    799         indices = self._fix_pt_indices(indices)

/usr/lib/python2.3/site-packages/numarray/generic.py in
_takeShape(scattered, indexArrays)
    133         nShape = scattered._shape[-leftOver:]
    134         if scattered.isbyteswapped() or not
scattered.iscontiguous():
--> 135             raise ValueError("Invalid destination array:
partial indices require contiguous non-byteswapped destination")
    136     else:
    137         N = scattered._itemsize

ValueError: Invalid destination array: partial indices require
contiguous non-byteswapped destination






More information about the NumPy-Discussion mailing list