From: Jon S. <js...@wm...> - 2001-01-29 14:46:58
|
Hello, there. I needed last Saturday a function which returns the greatest/smallest element of a NumPy array. I seeked through the documentation and found the argmax/argmin functions. However, they must be called recursively to find the greatest(smallest) element of a multidimendional array. As I needed to process a BIG dataset of multidimensional arrays, I wrote a function in C which returns as a NumPy array shaped (2,) the [smallest one,biggest one] elements in an arbitrarily shaped NumPy array. It is pure C and works for multidimensional arrays. The return typecode is the same of the input array (except with complex numbers, which compare numbers through their modules). I can make this function available to general public by means of my WEB page or my starship account as a module. However, I wonder: a) Is this a wheel already invented some 40,000 years ago? May be I missed something in the manual? b) If the answer to the previous question is NO, would you (main developers) be interested in making it available as one of the "general purpose" NumPy functions? It is quite general-purpose, indeed. I have needed it five times or so in the last two years... Looking after your comments. Jon Saenz. | Tfno: +34 946012470 Depto. Fisica Aplicada II | Fax: +34 944648500 Facultad de Ciencias. \\ Universidad del Pais Vasco \\ Apdo. 644 \\ 48080 - Bilbao \\ SPAIN |
From: Paul F. D. <pa...@pf...> - 2001-01-29 15:27:08
|
>>> import Numeric >>> x=Numeric.arange(24) >>> x.shape=(3,2,4) >>> print Numeric.maximum.reduce(x.flat) 23 The .flat operator does not copy the data. -----Original Message----- From: num...@li... [mailto:num...@li...]On Behalf Of Jon Saenz Sent: Monday, January 29, 2001 6:47 AM To: Numpy-Discussion@Lists. Sourceforge. Net Subject: [Numpy-discussion] Is this a wheel? Hello, there. I needed last Saturday a function which returns the greatest/smallest element of a NumPy array. I seeked through the documentation and found the argmax/argmin functions. However, they must be called recursively to find the greatest(smallest) element of a multidimendional array. As I needed to process a BIG dataset of multidimensional arrays, I wrote a function in C which returns as a NumPy array shaped (2,) the [smallest one,biggest one] elements in an arbitrarily shaped NumPy array. It is pure C and works for multidimensional arrays. The return typecode is the same of the input array (except with complex numbers, which compare numbers through their modules). I can make this function available to general public by means of my WEB page or my starship account as a module. However, I wonder: a) Is this a wheel already invented some 40,000 years ago? May be I missed something in the manual? b) If the answer to the previous question is NO, would you (main developers) be interested in making it available as one of the "general purpose" NumPy functions? It is quite general-purpose, indeed. I have needed it five times or so in the last two years... Looking after your comments. Jon Saenz. | Tfno: +34 946012470 Depto. Fisica Aplicada II | Fax: +34 944648500 Facultad de Ciencias. \\ Universidad del Pais Vasco \\ Apdo. 644 \\ 48080 - Bilbao \\ SPAIN _______________________________________________ Numpy-discussion mailing list Num...@li... http://lists.sourceforge.net/lists/listinfo/numpy-discussion |
From: David P G. <dp...@lb...> - 2001-01-29 19:30:39
|
<html><head></head><body><br> So, what does one do for an array that is not contiguous?<br> Dave Grote<br> <br> Paul F. Dubois wrote:<br> <blockquote type="cite" cite="mid:ADE...@pf..."> <blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><pre wrap="">import Numeric<br>x=Numeric.arange(24)<br>x.shape=(3,2,4)<br>print Numeric.maximum.reduce(x.flat)<br></pre></blockquote></blockquote></blockquote> <pre wrap=""><!---->23<br><br>The .flat operator does not copy the data. <br>-----Original Message-----<br>From: <a class="moz-txt-link-abbreviated" href="mailto:num...@li...">num...@li...</a><br>[<a class="moz-txt-link-freetext" href="mailto:num...@li...">mailto:num...@li...</a>]On Behalf Of Jon<br>Saenz<br>Sent: Monday, January 29, 2001 6:47 AM<br>To: <a class="moz-txt-link-abbreviated" href="mailto:Numpy-Discussion@Lists">Numpy-Discussion@Lists</a>. Sourceforge. Net<br>Subject: [Numpy-discussion] Is this a wheel?<br><br><br>Hello, there.<br><br>I needed last Saturday a function which returns the greatest/smallest<br>element of a NumPy array. I seeked through the documentation and found the<br>argmax/argmin functions. However, they must be called recursively to find<br>the greatest(smallest) element of a multidimendional array. As I needed t! ! o<br>process a BIG dataset of multidimensional arrays, I wrote a function in C<br>which returns as a NumPy array shaped (2,) the [smallest one,biggest one]<br>elements in an arbitrarily shaped NumPy array. It is pure C and works for<br>multidimensional arrays. The return typecode is the same of the input<br>array (except with complex numbers, which compare numbers through their<br>modules).<br><br>I can make this function available to general public by means of my WEB<br>page or my starship account as a module. However, I wonder:<br>a) Is this a wheel already invented some 40,000 years ago? May be I missed<br>something in the manual?<br>b) If the answer to the previous question is NO, would you (main<br>developers) be interested in making it available as one of the "general<br>purpose" NumPy functions? It is quite general-purpose, indeed. I have<br>needed it five times or so in the last two years...<br><br>Looking after your comments.<br><br><br>Jon Saenz. | Tfno: +34 94601! ! 2470<br>Depto. Fisica Aplicada II | Fax: +34 944648500<br>Facultad de Ciencias. \\ Universidad del Pais Vasco \\<br>Apdo. 644 \\ 48080 - Bilbao \\ SPAIN<br><br><br>_______________________________________________<br>Numpy-discussion mailing list<br><a class="moz-txt-link-abbreviated" href="mailto:Num...@li...">Num...@li...</a><br><a class="moz-txt-link-freetext" href="http://lists.sourceforge.net/lists/listinfo/numpy-discussion">http://lists.sourceforge.net/lists/listinfo/numpy-discussion</a><br><br><br>_______________________________________________<br>Numpy-discussion mailing list<br><a class="moz-txt-link-abbreviated" href="mailto:Num...@li...">Num...@li...</a><br><a class="moz-txt-link-freetext" href="http://lists.sourceforge.net/lists/listinfo/numpy-discussion">http://lists.sourceforge.net/lists/listinfo/numpy-discussion</a><br></pre> </blockquote> <br> </body></html> |
From: Konrad H. <hi...@cn...> - 2001-02-07 14:17:50
|
> element of a NumPy array. I seeked through the documentation and found the > argmax/argmin functions. However, they must be called recursively to find > the greatest(smallest) element of a multidimendional array. As I needed to You could run it on Numeric.ravel(array) (which shouldn't make a copy), and then reconstruct the multidimensional indices from the single index into the flattened array. The additional overhead should be minimal, and you don't need any C code. Konrad -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hi...@cn... Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- |
From: David P G. <dp...@lb...> - 2001-02-07 19:42:53
|
<html><head></head><body><br> Ravel does make a copy when the array is not contiguous. I asked this question before but didn't get any response - is there a way to get the argmax/min or max/min of a non-contiguous multi-dimensional array without making a contiguous copy? I use python as an interface to fortran code and so I am constantly dealing with arrays that are not contiguous, i.e. not with C ordering. Any help is appreciated.<br> Thanks,<br> Dave<br> <br> Konrad Hinsen wrote:<br> <blockquote type="cite" cite="mid:200...@ch..."> <blockquote type="cite"><pre wrap="">element of a NumPy array. I seeked through the documentation and found the<br>argmax/argmin functions. However, they must be called recursively to find<br>the greatest(smallest) element of a multidimendional array. As I needed to<br></pre></blockquote> <pre wrap=""><!----><br>You could run it on Numeric.ravel(array) (which shouldn't make a<br>copy), and then reconstruct the multidimensional indices from the<br>single index into the flattened array. The additional overhead<br>should be minimal, and you don't need any C code.<br><br>Konrad<br></pre> </blockquote> <br> </body></html> |
From: John J. L. <ph...@cs...> - 2001-02-08 08:58:41
|
On Wed, 7 Feb 2001, David P Grote wrote: > Ravel does make a copy when the array is not contiguous. I asked this > question before but didn't get any response - is there a way to get the > argmax/min or max/min of a non-contiguous multi-dimensional array without > making a contiguous copy? I use python as an interface to fortran code > and so I am constantly dealing with arrays that are not contiguous, i.e. > not with C ordering. Any help is appreciated. Aren't FORTRAN arrays just stored in the reverse order to C? Isn't this just dealt with by having the stride lengths of your Numeric array in the opposite order? Or does FORTRAN sometimes allocate multidimensional arrays with gaps in memory?? I don't see why they should not be contiguous. John |
From: David P G. <dp...@lb...> - 2001-02-08 17:40:33
|
<html><head></head><body><br> What I meant by "not contiguous" is that the Numeric flag "contiguous" is set to false. This flag is only true when Numeric arrays have their strides in C ordering. Any rearrangement of the strides causes the flag to be set to false - a transpose for example. The data in the fortran arrays is contiguous in memory. Here's an example using ravel.<br> <br> >>> from Numeric import *<br> >>> xx = ones((4,4))<br> >>> yy = ravel(xx)<br> >>> yy[2] = 6<br> >>> xx<br> array([[1, 1, 6, 1],<br> [1, 1, 1, 1],<br> [1, 1, 1, 1],<br> [1, 1, 1, 1]])<br> >>> zz = transpose(xx)<br> >>> zz<br> array([[1, 1, 1, 1],<br> [1, 1, 1, 1],<br> [6, 1, 1, 1],<br> [1, 1, 1, 1]])<br> >>> yy = ravel(zz)<br> >>> yy[2] = 10 <br> >>> zz<br> array([[1, 1, 1, 1],<br> [1, 1, 1, 1],<br> [6, 1, 1, 1],<br> [1, 1, 1, 1]])<br> >>> yy<br> array([ 1, 1, 10, 1, 1, 1, 1, 1, 6, 1, 1, 1, 1, 1, 1, 1])<br> <br> As you can see, the second ravel has made a copy, whereas the first did not. I know this is a minor point, and I apologize for taking up bandwidth, but it would be nice if there were a way around this, short of writing my own C routines for min and max.<br> Dave<br> <br> John J. Lee wrote:<br> <blockquote type="cite" cite="mid:Pin...@mi..."><pre wrap="">On Wed, 7 Feb 2001, David P Grote wrote:<br><br></pre> <blockquote type="cite"><pre wrap="">Ravel does make a copy when the array is not contiguous. I asked this<br>question before but didn't get any response - is there a way to get the<br>argmax/min or max/min of a non-contiguous multi-dimensional array without<br>making a contiguous copy? I use python as an interface to fortran code<br>and so I am constantly dealing with arrays that are not contiguous, i.e.<br>not with C ordering. Any help is appreciated.<br></pre></blockquote> <pre wrap=""><!----><br>Aren't FORTRAN arrays just stored in the reverse order to C? Isn't this<br>just dealt with by having the stride lengths of your Numeric array in the<br>opposite order? Or does FORTRAN sometimes allocate multidimensional<br>arrays with gaps in memory?? I don't see why they should not be<br>contiguous.<br><br><br>John<br><br></pre> </blockquote> <br> </body></html> |
From: John J. L. <ph...@cs...> - 2001-02-08 21:01:25
|
On Thu, 8 Feb 2001, David P Grote wrote: > What I meant by "not contiguous" is that the=A0 Numeric flag "contiguous" > is set to false. This flag is only true when Numeric arrays have their > strides in C ordering. Any rearrangement of the strides causes the flag > to be set to false - a transpose for example. The data in the fortran > arrays is contiguous in memory. Here's an example using ravel. [...] Oh, I see. > Ravel does make a copy when the array is not contiguous. I asked this > question before but didn't get any response - is there a way to get the > argmax/min or max/min of a non-contiguous multi-dimensional array without > making a contiguous copy? I use python as an interface to fortran code > and so I am constantly dealing with arrays that are not contiguous, i.e. > not with C ordering. Any help is appreciated. I don't know about doing it with one of the Numeric functions, but it's very easy to write in C -- just this week I wrote a max() that works on (contiguous or not) Numeric arrays. I think I wrote it as a C function (not callable from Python) for the function I was wrapping to use, but it would be easy to change it to be a proper Python function. I'll mail you a copy if you like. John |