R中指数的多重求和

R中指数的多重求和,r,sum,R,Sum,我可能会放一些样本数据,但我不知道如何在R中解释下面的图像的第一件事 我看过 但是无法推断出我的问题的答案。您可以使用aperm并利用矢量化。您必须指出哪些是“通用”维度(即X和C中包含的维度)、排列X和相乘。比如: #declare which are the dimensions in X common to C commonDims<-c(3,4) #the other dimensions are the "uncommon" ones uncommonDims<-set

我可能会放一些样本数据,但我不知道如何在R中解释下面的图像的第一件事

我看过


但是无法推断出我的问题的答案。

您可以使用
aperm
并利用矢量化。您必须指出哪些是“通用”维度(即
X
C
中包含的维度)、排列
X
和相乘。比如:

#declare which are the dimensions in X common to C
commonDims<-c(3,4)
#the other dimensions are the "uncommon" ones
uncommonDims<-setdiff(seq_along(dims),commonDims)
#then you can get the sum
sum(as.vector(aperm(X,c(commonDims,uncommonDims)))*as.vector(C))

您可以使用
aperm
并利用矢量化。您必须指出哪些是“通用”维度(即
X
C
中包含的维度)、排列
X
和相乘。比如:

#declare which are the dimensions in X common to C
commonDims<-c(3,4)
#the other dimensions are the "uncommon" ones
uncommonDims<-setdiff(seq_along(dims),commonDims)
#then you can get the sum
sum(as.vector(aperm(X,c(commonDims,uncommonDims)))*as.vector(C))