Home > Archive > Fortran > July 2004 > maxloc/minloc functions
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
maxloc/minloc functions
|
|
| tachyon 2004-07-08, 3:56 am |
| Hi all,
Assuming that I use the maxloc/minloc functions to extract the locations of
the maximum and minimum values in a 2-dimensional array, is there a simple
way to get only the row number for the array elements from the results (as
I'm only really interested in the row that contains the maximum value for a
given column).
If it's of any consequence I'm using f90.
Would greatly appreciate any help as I'm still relatively new to fortran!
| |
| James Van Buskirk 2004-07-08, 3:56 am |
| "tachyon" <tachyon_master@NO_SPAM@hotmail.com> wrote in message
news:40ecaee4$1@news.jcu.edu.au...
> Assuming that I use the maxloc/minloc functions to extract the locations
of
> the maximum and minimum values in a 2-dimensional array, is there a simple
> way to get only the row number for the array elements from the results (as
> I'm only really interested in the row that contains the maximum value for
a
> given column).
If you look at
http://h18009.www1.hp.com/fortran/d...m#maxloc_intrin
the last example on the page does what I think you want to do.
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
| |
| tachyon 2004-07-08, 3:56 am |
| Not quite...
Say I have the following,
A=[1 2 3 4
7 6 5 4
3 5 7 9]
I want to find the maximum value in the fourth column (which is 9). That's
easy to do. Now is there a way to determine the individual row number that
the particular value occurs on (which is obviously the third row)?
"James Van Buskirk" <not_valid@comcast.net> wrote in message
news:Yu2Hc.41032$a24.16559@attbi_s03...
> If you look at
>
> http://h18009.www1.hp.com/fortran/d...m#maxloc_intrin
>
> the last example on the page does what I think you want to do.
| |
| James Giles 2004-07-08, 3:56 am |
| tachyon wrote:
> Not quite...
>
> Say I have the following,
>
> A=[1 2 3 4
> 7 6 5 4
> 3 5 7 9]
>
> I want to find the maximum value in the fourth column (which is 9).
> That's easy to do. Now is there a way to determine the individual row
> number that the particular value occurs on (which is obviously the third
> row)?
Well, how about :
dot_product(maxloc(a,dim=1),(/0,0,0,1/))
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
| |
| tachyon 2004-07-08, 3:56 am |
| Works perfectly! Many thanks :-)
"James Giles" <jamesgiles@worldnet.att.net> wrote in message
news:wK3Hc.71396$OB3.55194@bgtnsc05-news.ops.worldnet.att.net...
> Well, how about :
>
> dot_product(maxloc(a,dim=1),(/0,0,0,1/))
>
> --
> J. Giles
| |
| James Van Buskirk 2004-07-08, 4:03 pm |
| "James Giles" <jamesgiles@worldnet.att.net> wrote in message
news:wK3Hc.71396$OB3.55194@bgtnsc05-news.ops.worldnet.att.net...
> dot_product(maxloc(a,dim=1),(/0,0,0,1/))
I confess that I simply don't get what you guys are doing.
However:
maxloc(a(:,4))
Or am I still out of touch?
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
| |
| Richard Maine 2004-07-08, 4:03 pm |
| "James Van Buskirk" <not_valid@comcast.net> writes:
> "James Giles" <jamesgiles@worldnet.att.net> wrote in message
> news:wK3Hc.71396$OB3.55194@bgtnsc05-news.ops.worldnet.att.net...
>
>
> I confess that I simply don't get what you guys are doing.
> However:
>
> maxloc(a(:,4))
>
> Or am I still out of touch?
That one seems a *LOT* more readable to me. I was going to suggest
that if the other was used, it be done only with a comment. But I
didn't think about it enough to come up with the more direct solution
(anyway that sounds like a better excuse than just saying that I
was too dense to do so. :-)).
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
| |
| James Giles 2004-07-08, 4:03 pm |
| Richard Maine wrote:
> "James Van Buskirk" <not_valid@comcast.net> writes:
>
>
> That one seems a *LOT* more readable to me. I was going to suggest
> that if the other was used, it be done only with a comment. But I
> didn't think about it enough to come up with the more direct solution
> (anyway that sounds like a better excuse than just saying that I
> was too dense to do so. :-)).
Well it was very late when I wrote the above, but not so
late that I'd get the wrong rank. The solution I thought
of about 15 minutes later was:
sum(maxloc(a(:,4))
That would work in F90 implementations. For f95 and
beyond:
maxloc(a(:,4),dim=1)
It seemed to me that's what the question was about : how to
get a scalar from the intrinsic.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
| |
|
| James Giles <jamesgiles@worldnet.att.net> wrote:
> Well it was very late when I wrote the above, but not so
> late that I'd get the wrong rank. The solution I thought
> of about 15 minutes later was:
> sum(maxloc(a(:,4))
> That would work in F90 implementations. For f95 and
> beyond:
> maxloc(a(:,4),dim=1)
> It seemed to me that's what the question was about : how to
> get a scalar from the intrinsic.
Both of those seem to require that you know the value of the
column with the largest value. Which was similar to what the
OP wanted in the first place (value of the row).
How about :
maxloc(pack(a,.TRUE.))/size(a,2)
Cheerio
Aidan
--
Remove famous (dead) Italian author plus full-stop to send me email (don't
blame me about the spelling of Alighieri -- it is the sy min's fault!)
------------ And now a word from our sponsor ------------------
For a quality usenet news server, try DNEWS, easy to install,
fast, efficient and reliable. For home servers or carrier class
installations with millions of users it will allow you to grow!
---- See http://netwinsite.com/sponsor/sponsor_dnews.htm ----
|
|
|
|
|