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.
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
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.
1 解答
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.
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
链接已复制
4 回复数
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.
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.
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.
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
