
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

The .flat operator does not copy the data. -----Original Message----- From: numpy-discussion-admin@lists.sourceforge.net [mailto:numpy-discussion-admin@lists.sourceforge.net]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 Numpy-discussion@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion

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: hinsen@cnrs-orleans.fr 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 -------------------------------------------------------------------------------

On Wed, 7 Feb 2001, David P Grote wrote:
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

On Thu, 8 Feb 2001, David P Grote wrote:
Oh, I see.
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

The .flat operator does not copy the data. -----Original Message----- From: numpy-discussion-admin@lists.sourceforge.net [mailto:numpy-discussion-admin@lists.sourceforge.net]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 Numpy-discussion@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpy-discussion

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: hinsen@cnrs-orleans.fr 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 -------------------------------------------------------------------------------

On Wed, 7 Feb 2001, David P Grote wrote:
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

On Thu, 8 Feb 2001, David P Grote wrote:
Oh, I see.
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
participants (5)
-
David P Grote
-
John J. Lee
-
Jon Saenz
-
Konrad Hinsen
-
Paul F. Dubois