Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
公告
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
初学者
763 次查看
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 项奖励
1 解答
DavidWhite
重要分销商 II
763 次查看
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 项奖励
4 回复数
yingwu
初学者
763 次查看


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

Ying
0 项奖励
TimP
名誉分销商 III
763 次查看
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 项奖励
DavidWhite
重要分销商 II
764 次查看
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 项奖励
yingwu
初学者
763 次查看

Hi David,

Yes, it works. Thanks very very much. Actually, clever idea.
0 项奖励
回复