<br><br>On Monday, January 9, 2012, questions anon <<a href="mailto:questions.anon@gmail.com">questions.anon@gmail.com</a>> wrote:<br>> thanks for the responses.<br>> Unfortunately they are not matching shapes<br>
>>>> print TSFC.shape, TIME.shape, LAT.shape, LON.shape<br>> (721, 106, 193) (721,) (106,) (193,)<br>><br>> So I still receive index out of bounds error:<br>>>>>tmax=TSFC.max(axis=0)<br>> numpy array of max values for the month<br>
>>>>maxindex=tmax.argmax()<br>> 2928<br>>>>>maxtemp=tmax.ravel()[maxindex] #or maxtemp=TSFC.max()<br>> 35.5 (degrees celcius)<br>><br>>>>>latloc=LAT[tmax.argmax()]<br>> IndexError: index out of bounds<br>
><br>> lonloc=LON[tmax.argmax()]<br>> timeloc=TIME[tmax.argmax()]<br>><br>><br>> Any other ideas for this type of situation?<br>> thanks<br><br>Right, we realize they are not the same shape.  When you use argmax on the temperature data, take that index number and use unravel_index(index, TSFC.shape) to get a three-element tuple, each being the index in the TIME, LAT, LON arrays, respectively.<br>
<br>Cheers,<br>Ben Root<br><br>><br>> On Wed, Jan 4, 2012 at 10:29 PM, Derek Homeier <<a href="mailto:derek@astro.physik.uni-goettingen.de">derek@astro.physik.uni-goettingen.de</a>> wrote:<br>>><br>>> On 04.01.2012, at 5:10AM, questions anon wrote:<br>
>><br>>> > Thanks for your responses but I am still having difficuties with this problem. Using argmax gives me one very large value and I am not sure what it is.<br>>> > There shouldn't be any issues with the shape. The latitude and longitude are the same shape always (covering a state) and the temperature (TSFC) data are hourly for a whole month.<br>
>><br>>> There will be an issue if not TSFC.shape == TIME.shape == LAT.shape == LON.shape<br>>><br>>> One needs more information on the structure of these data to say anything definite,<br>>> but if e.g. your TSFC data have a time and a location dimension, argmax will<br>
>> per default return the index for the flattened array (see the argmax documentation<br>>> for details, and how to use the axis keyword to get a different output).<br>>> This might be the very large value you mention, and if your location data have fewer<br>
>> dimensions, the index will easily be out of range. As Ben wrote, you'd need extra work to<br>>> find the maximum location, depending on what maximum you are actually looking for.<br>>><br>>> As a speculative example, let's assume you have the temperature data in an<br>
>> array(ntime, nloc) and the position data in array(nloc). Then<br>>><br>>> TSFC.argmax(axis=1)<br>>><br>>> would give you the index for the hottest place for each hour of the month<br>>> (i.e. actually an array of ntime indices, and pointer to so many different locations).<br>
>><br>>> To locate the maximum temperature for the entire month, your best way would probably<br>>> be to first extract the array of (monthly) maximum temperatures in each location as<br>>><br>>> tmax = TSFC.max(axis=0)<br>
>><br>>> which would have (in this example) the shape (nloc,), so you could directly use it to index<br>>><br>>> LAT[tmax.argmax()]   etc.<br>>><br>>> Cheers,<br>>>                                                Derek<br>
>><br>>> _______________________________________________<br>>> NumPy-Discussion mailing list<br>>> <a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>>> <a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
><br>>