Re: Faster way to map numpy arrays

Discussion in 'Python' started by Stefan Behnel, Jun 25, 2012.

  1. Saurabh Kabra, 25.06.2012 05:37:
    > I have written a script to map a 2D numpy array(A) onto another array(B) of
    > different dimension. more than one element (of array A) are summed and
    > mapped to each element of array B. To achieve this I create a list where I
    > store the index of array A to be mapped to array B. The list is the
    > dimension of array B (if one can technically say that) and each element is
    > a list of indices to be summed. Then I parse this list with a nested loop
    > and compute each element of array B.
    >
    > Because of the nested loop and the big arrays the process takes a minute or
    > so. My question is: is there a more elegant and significantly faster way of
    > doing this in python?


    I'm sure there's a way to do this kind of transformation more efficiently
    in NumPy. I faintly recall that you can use one array to index into
    another, something like that might do the trick already. In any case, using
    a NumPy array also for the mapping matrix sounds like a straight forward
    thing to try.

    But you might also want to take a look at Cython. It sounds like a problem
    where a trivial Cython implementation would seriously boost the performance.

    http://docs.cython.org/src/tutorial/numpy.html

    Stefan
     
    Stefan Behnel, Jun 25, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. drife
    Replies:
    1
    Views:
    367
    Travis E. Oliphant
    Mar 1, 2006
  2. Duncan Smith
    Replies:
    3
    Views:
    423
    Duncan Smith
    Apr 25, 2007
  3. Replies:
    2
    Views:
    492
    Robert Kern
    Nov 13, 2007
  4. W. eWatson
    Replies:
    2
    Views:
    945
    W. eWatson
    Nov 23, 2009
  5. Javier Montoya

    numpy arrays to python compatible arrays

    Javier Montoya, Jun 10, 2010, in forum: Python
    Replies:
    3
    Views:
    450
    Javier Montoya
    Jun 12, 2010
Loading...

Share This Page