我想使用单行语句在Fortran中执行以下伪代码的 do-end do 位:
integer, parameter :: N = 1000
integer, dimension(1:N) :: ArrayA, ArrayB
logical, dimension(1:N) :: ArrayL
...
...
do i = 1, N
if( ArrayA(i) <= ArrayB(i) ) then
ArrayL(i) = .true.
else
ArrayL(i) = .false.
end if
end do
这可能吗?如果是这样,我该怎么做?
答案 0 :(得分:3)
integer, parameter :: N = 1000
integer, dimension(1:N) :: ArrayA, ArrayB
logical, dimension(1:N) :: ArrayL
...
...
ArrayL = (ArrayA <= ArrayB)
答案 1 :(得分:0)
integer, parameter :: N = 1000
integer, dimension(1:N) :: ArrayA, ArrayB
logical, dimension(1:N) :: The_Mask_Where_A_lt_B = .FALSE.
integer :: Some_MinVal
...
...
WHERE(ArrayA <= ArrayB) The_Mask_Where_A_lt_B = .TRUE.
!I know that this is not part of the question...
Some_MinVal = MINVAL(ArrayA, MASK=The_Mask_Where_A_lt_B)