相关疑难解决方法(0)

Fortran对R中的for-loop等仲裁索引进行了循环操作?

我有两个p倍-N阵列xmissx,其中x包含任意数目和missx是包含零和一的阵列.我需要对missx零点进行递归计算.显而易见的解决方案是这样的:

do i = 1, n
   do j = 1, p
      if(missx(j,i)==0) then
         z(j,i) = ... something depending on the previous computations and x(j,i)
      end if
   end do
end do
Run Code Online (Sandbox Code Playgroud)

这种方法的问题在于大部分时间missx总是为0,因此有很多if陈述总是如此.

在R中,我会这样做:

for(i in 1:n)
  for(j in which(xmiss[,i]==0))
     z[j,i] <- ... something depending on the previous computations and x[j,i]
Run Code Online (Sandbox Code Playgroud)

有没有办法在Fortran中进行内循环?我确实试过这样的版本:

do i = 1, n
   do j = 1, xlength(i) !xlength(i) gives the number of zero-elements …
Run Code Online (Sandbox Code Playgroud)

fortran loops if-statement r

2
推荐指数
1
解决办法
440
查看次数

标签 统计

fortran ×1

if-statement ×1

loops ×1

r ×1