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 on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Q2: about maxloc(). HELP!!!

yingwu
Beginner
762 Views
Hi, here is my another question. I define two arrays,

real :: A(10,5), B(1,5)

After setting values to both the arrays, I know I can use maxLoc(B) to find the index of the cell with maximal value in array B and the result of maxloc(B) is an array of type integer. In this case, the result should be a (1,1) integer array. Then I can access the corresponding column values from array A, which is like

A(:,maxloc(B)) ! this should return one column of array A

Now I want to copy the column values in array A that corresponds to the maximal value in array B to a new array, so I define another array,

real :: C(10,1)

and set

C=A(:,maxloc(B))

However, I have the error, "error #6366: The shapes of the array expressions do not conform ". Is there any mistake? However can I do this?!!!!!!!!!!!!!!



The funny thing is that if I use C=A(:,1), I have the same error. If I use C(:,1)=A(:,1), it is OK. But I tried C(:,1)=A(:,maxloc(B)), I get the same error again.

Thanks very much.
0 Kudos
1 Solution
DavidWhite
Valued Contributor II
762 Views
In your post, you said ...

The funny thing is that if I use C=A(:,1), I have the same error. If I use C(:,1)=A(:,1), it is OK. But I tried C(:,1)=A(:,maxloc(B)), I get the same error again.

But you also said that maxloc(B) is a (1,1) array.

In A(:,1) you are using a scalar argument, so this cannot be the same as A(:,maxloc(B)) as you are trying to use an array argument.

I have done something similar to try and convert the array to a scalar by using the sum function, and so

A(:,Sum(Maxloc(B)))

may work for you.


Regards,


David

View solution in original post

0 Kudos
4 Replies
yingwu
Beginner
762 Views


Is there anybody who can give me some suggestion as it looks very confusing? Thanks very much.

Ying
0 Kudos
TimP
Honored Contributor III
762 Views
Maybe everyone is confused about what you are trying to do.
Possibly, you want to use the DIM argument in some of your examples, so that MAXLOC is assured to give a scalar result.
Your textbook, as well as the ifort documentation, should have examples, and some are available by web search.
0 Kudos
DavidWhite
Valued Contributor II
763 Views
In your post, you said ...

The funny thing is that if I use C=A(:,1), I have the same error. If I use C(:,1)=A(:,1), it is OK. But I tried C(:,1)=A(:,maxloc(B)), I get the same error again.

But you also said that maxloc(B) is a (1,1) array.

In A(:,1) you are using a scalar argument, so this cannot be the same as A(:,maxloc(B)) as you are trying to use an array argument.

I have done something similar to try and convert the array to a scalar by using the sum function, and so

A(:,Sum(Maxloc(B)))

may work for you.


Regards,


David
0 Kudos
yingwu
Beginner
762 Views

Hi David,

Yes, it works. Thanks very very much. Actually, clever idea.
0 Kudos
Reply