How to dynamically access Numeric subarrays

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue Aug 3 08:55:22 EDT 2004


>>>>> "Gaubitzer" == Gaubitzer Erwin <a9605473 at unet.univie.ac.at> writes:

    Gaubitzer> The problem is that the input data varies in its
    Gaubitzer> dimensions so my wanted data can appear at different
    Gaubitzer> positions of the array. I tried to create a list with
    Gaubitzer> the slice on the appropriate position to use it as
    Gaubitzer> indices list in the array but this failed.

    Gaubitzer> So my questions to out there: How can I extract a
    Gaubitzer> (Numeric Python) subarray whose indices have to be
    Gaubitzer> built dynamically.

In Numeric, use the take function

    >>> x = arange(100)
    >>> ind = [23,24,25]
    >>> take(x,ind)
    array([23, 24, 25])

In numarray, you can use index arrays.  See section 4.8 of the
numarray manual for more information -
http://www.stsci.edu/resources/software_hardware/numarray/manualPDF

    >>> x = arange(100)
    >>> ind = array([23,24,25])
    >>> x[ind]
    array([23, 24, 25])

Cheers, 
JDH




More information about the Python-list mailing list