3D array -> apply -> 3D array

前提是你 提交于 2019-12-05 14:39:44

Here is a less than fantastic solution that requires foreknowledge of the dimensions of the function result matrix:

vapply(
  1:dim(arr)[3], 
  function(x, y) arr[,,x] %*% y, 
  FUN.VALUE=arr[,,1], 
  y=cols.shuf.mx
) 

If you read the help page for apply, it basically agrees with your first sentence. It is set up with a particular design and you would need to construct a new function to do something differently. BTW: This gives you the same result much more simply than that aperm(aaply(...)) rigamarole:

arr[ , c(2,1,4,3)  , ]
#-------------------------
, , c = c1

    b
a           b2        b1        b4        b3
  a1 0.4089769 0.2875775 0.5281055 0.9404673
  a2 0.8830174 0.7883051 0.8924190 0.0455565

, , c = c2

    b
a           b2        b1        b4        b3
  a1 0.9568333 0.5514350 0.1029247 0.6775706
  a2 0.4533342 0.4566147 0.8998250 0.5726334

, , c = c3

    b
a           b2         b1        b4        b3
  a1 0.3279207 0.24608773 0.6405068 0.8895393
  a2 0.9545036 0.04205953 0.9942698 0.6928034
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!