473,387 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

numpy : argmin in multidimensional arrays

TG
Hi there.

I am working with multi-dimensional arrays and I need to get
coordinates of the min value in it.

using myarray.argmin() returns the index in the flatten array, which is
a first step, but I wonder if it is possible to get the coordinates
directly as an array, rather than calculating them myself by using this
flat index and the shape of the array.

well, in fact i'm not sure to understand how argmin(myarray) works,
when myarray is multidimensional.

Thanks

Jul 6 '06 #1
2 20472
TG wrote:
Hi there.

I am working with multi-dimensional arrays and I need to get
coordinates of the min value in it.

using myarray.argmin() returns the index in the flatten array, which is
a first step, but I wonder if it is possible to get the coordinates
directly as an array, rather than calculating them myself by using this
flat index and the shape of the array.

well, in fact i'm not sure to understand how argmin(myarray) works,
when myarray is multidimensional.

By default, the argmin method flattens the array and returns the flat
index. You can get the corresponding element using

myarray.flat[index]

Alternatively, you can use the function unravel_index

unravel_index(flat_index, myarray.shape)

to return an N-dimensional index.
If you give an axis argument, then the minimum is found along the
specified dimension and you get an N-1 dimensional array of indices that
will all be between 1 and myarray.shape[axis]
-Travis

Jul 6 '06 #2
TG
thanks. unravel_index do the trick.

Travis E. Oliphant wrote:
TG wrote:
Hi there.

I am working with multi-dimensional arrays and I need to get
coordinates of the min value in it.

using myarray.argmin() returns the index in the flatten array, which is
a first step, but I wonder if it is possible to get the coordinates
directly as an array, rather than calculating them myself by using this
flat index and the shape of the array.

well, in fact i'm not sure to understand how argmin(myarray) works,
when myarray is multidimensional.


By default, the argmin method flattens the array and returns the flat
index. You can get the corresponding element using

myarray.flat[index]

Alternatively, you can use the function unravel_index

unravel_index(flat_index, myarray.shape)

to return an N-dimensional index.
If you give an axis argument, then the minimum is found along the
specified dimension and you get an N-1 dimensional array of indices that
will all be between 1 and myarray.shape[axis]
-Travis
Jul 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: doodle4 | last post by:
Hello all, I am trying to convert some C code into python. Since i am new to python, i would like to know how to deal with multidimensional arrays? Thanks, -Joe Here's a snippet of what i...
2
by: Terry | last post by:
Hi, can someone plz tell me how multidimensional arrays (like a 2-D array) are stored in memory? Are they like single dimensional arrays? Stored sequentially in one "row", so to say? Thanks ...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
5
by: whisper | last post by:
Hi: there is an issue that confuses me and the FAQ did not clarify it for me. (Sorry I am just learning!) Let say I define a multidimensional array in my main routine as follows: int...
3
by: matthewburton | last post by:
Hi everyone, I'm trying to write a program that will search a body of text and replace certain words (say, A, B, and C) with different words that I think are more appropriate (A1, B1 and C1). I...
21
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
9
by: barmy_mad | last post by:
Hi I new to C# and trying to store/extract a collection of multidimensional arrays. For example; string a_DATA = new string object o_CON = new object for(int i=0;i<10;i++){ for(int...
5
by: asdf | last post by:
I was told not to use the low-level language such as arrays which inherited from C, I want to know what can I use to substitute the C-style multidimensional arrays? Is there multidimensional vector?
2
by: oopsatwork | last post by:
Ok...so, I have been outside of the C world for a _very_ long time...but not so long as to remember how to do multidimensional arrays. So, let me state that I know how to malloc pointers to...
12
by: filippo nanni | last post by:
Hello everybody, my question is this: I have two multidimensional arrays and I have to create a third one (for later use) from comparing these two. Here is my example code: //BEGIN CODE var...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.