[Numpy-discussion] Replacing values based on index

Pinner, Luke Luke.Pinner@environment.gov...
Thu Aug 12 00:19:43 CDT 2010

Apologies if this has been asked many times before, but I'm having
trouble even coming up with the right terms to search on.

I have an x,y,date stack of satellite images from which I need to know
on what date the max and min values occur. I can calculate the index at
which the min/max values occur, but how do I join that back to the date?

A simple example case:

import numpy as np

#Date when image was captured,
#images are in the stack in this order
days=[10, 20, 31, 41, 51, 59, 69, 79, 90, 100]

#dummy array representing something like
indexmin=np.array([[0, 2, 1],
                   [6, 7, 3],
                   [5, 5, 8]])

#I want to convert indexmin to "daymin" i.e
#[[10, 31, 20],
# [69, 79, 41],
# [59, 59, 90]]
#Where the each element of indexmin represent the value
#at the corresponding index in the days list/array.

#What I am currently doing is below,
#which is _rather_ slow on large arrays
#as I'm calling np.where len(days) times
for i,d in enumerate(days):

Any better suggestions?

Luke Pinner

If you have received this transmission in error please notify us immediately by return e-mail and delete all copies. If this e-mail or any attachments have been sent to you in error, that error does not constitute waiver of any confidentiality, privilege or copyright in respect of information in the e-mail or attachments. 

Please consider the environment before printing this email.


More information about the NumPy-Discussion mailing list