The "out=a" keyword will ensure your first array will keep being updated. So you can do something like:<br><br>a = my_list_of_arrays[0]<br>for b in my_list_of_arrays[1:]:<br>  numpy.maximum(a, b, out=a)<br><br>-=- Olivier<br>
<br><div class="gmail_quote">2011/12/6 questions anon <span dir="ltr"><<a href="mailto:questions.anon@gmail.com">questions.anon@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
thanks for all of your help, that does look appropriate but I am not sure how to loop it over thousands of files. <br>I need to keep the first array to compare with but replace any greater values as I loop through each array comparing back to the same array. does that make sense? <br>
<div class="HOEnZb"><div class="h5">
<br><br><div class="gmail_quote">On Wed, Dec 7, 2011 at 1:12 PM, Olivier Delalleau <span dir="ltr"><<a href="mailto:shish@keba.be" target="_blank">shish@keba.be</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

Thanks, I didn't know you could specify the out array :)<br><br>(to the OP: my initial suggestion, although probably not very efficient, seems to work with 2D arrays too, so I have no idea why it didn't work for you -- but Nathaniel's one seems to be the ideal one anyway).<span><font color="#888888"><br>


<br>-=- Olivier</font></span><div><div><br><br><div class="gmail_quote">2011/12/6 Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<p>I think you want<br>
  np.maximum(a, b, out=a)</p><span><font color="#888888">
<p>- Nathaniel</p></font></span><div><div>
<div class="gmail_quote">On Dec 6, 2011 9:04 PM, "questions anon" <<a href="mailto:questions.anon@gmail.com" target="_blank">questions.anon@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



thanks for responding Josef but that is not really what I am looking for, I have a multidimensional array and if the next array has any values greater than what is in my first array I want to replace them. The data are contained in netcdf files. <br>




I can achieve what I want if I combine all of my arrays using numpy concatenate and then using the command numpy.max(myarray, axis=0) but because I have so many arrays I end up with a memory error so I need to find a way to get the maximum while looping. <br>




<br><br><br><div class="gmail_quote">On Wed, Dec 7, 2011 at 12:36 PM,  <span dir="ltr"><<a href="mailto:josef.pktd@gmail.com" target="_blank">josef.pktd@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div><div>On Tue, Dec 6, 2011 at 7:55 PM, Olivier Delalleau <<a href="mailto:shish@keba.be" target="_blank">shish@keba.be</a>> wrote:<br>
> It may not be the most efficient way to do this, but you can do:<br>
> mask = b > a<br>
> a[mask] = b[mask]<br>
><br>
> -=- Olivier<br>
><br>
> 2011/12/6 questions anon <<a href="mailto:questions.anon@gmail.com" target="_blank">questions.anon@gmail.com</a>><br>
>><br>
>> I would like to produce an array with the maximum values out of many<br>
>> (10000s) of arrays.<br>
>> I need to loop through many multidimentional arrays and if a value is<br>
>> larger (in the same place as the previous array) then I would like that<br>
>> value to replace it.<br>
>><br>
>> e.g.<br>
>> a=[1,1,2,2<br>
>> 11,2,2<br>
>> 1,1,2,2]<br>
>> b=[1,1,3,2<br>
>> 2,1,0,0<br>
>> 1,1,2,0]<br>
>><br>
>> where b>a replace with value in b, so the new a should be :<br>
>><br>
>> a=[1,1,3,2]<br>
>> 2,1,2,2<br>
>> 1,1,2,2]<br>
>><br>
>> and then keep looping through many arrays and replace whenever value is<br>
>> larger.<br>
>><br>
>> I have tried numpy.putmask but that results in<br>
>> TypeError: putmask() argument 1 must be numpy.ndarray, not list<br>
>> Any other ideas? Thanks<br>
<br>
</div></div>if I understand correctly it's a minimum.reduce<br>
<br>
numpy<br>
<br>
>>> a = np.concatenate((np.arange(5)[::-1], np.arange(5)))*np.ones((4,3,1))<br>
>>> np.minimum.reduce(a, axis=2)<br>
array([[ 0.,  0.,  0.],<br>
       [ 0.,  0.,  0.],<br>
       [ 0.,  0.,  0.],<br>
       [ 0.,  0.,  0.]])<br>
>>> a.T.shape<br>
(10, 3, 4)<br>
<br>
python with iterable<br>
<br>
>>> reduce(np.maximum, a.T)<br>
array([[ 4.,  4.,  4.,  4.],<br>
       [ 4.,  4.,  4.,  4.],<br>
       [ 4.,  4.,  4.,  4.]])<br>
>>> reduce(np.minimum, a.T)<br>
array([[ 0.,  0.,  0.,  0.],<br>
       [ 0.,  0.,  0.,  0.],<br>
       [ 0.,  0.,  0.,  0.]])<br>
<br>
Josef<br>
<div><div><br>
>><br>
>> _______________________________________________<br>
>> NumPy-Discussion mailing list<br>
>> <a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
>> <a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
> <a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
><br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div>
</div></div><br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br>
</div></div><br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br>
</div></div><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" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br>