Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.

getting indexes of an array

yingwu
Beginner
602 Views
Hi, could I get the indexes of elements in an array that satisfies the defined condition. For example,

I have an array, A=(/3,6,1,2,7/)

I want to know the positions of elements that is greater than 3, the result should be

(/2,5/)

Thanks very much and I think this is a useful function.
0 Kudos
2 Replies
Les_Neilson
Valued Contributor II
602 Views

integer, allocatable :: ar(:)
allocate ar(size(a))
! Location (subscripts) of elements > 3
ar = maxloc(a, MASK=a>3)



Lookup maxloc and minloc in the help

Les
0 Kudos
yingwu
Beginner
602 Views
Les, I guess no.

I use print *, maxloc(a, MASK=a>3). The result has only one value. I guess this means: find the position of the element that has the maximal value from a set of elements whose values are greater than 3 in the array. So a sub-array whose values are greater than 3 is cut from the oringinal array and then find position.

Or I think I should be wrong.



0 Kudos
Reply