对数组列表求和 [英] Sum a list of arrays

查看:153
本文介绍了对数组列表求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多相同尺寸的数组:

I have a large list of arrays of the same dimension:

a<-array(NA,dim=c(2,4,3))
b<-array(NA,dim=c(2,4,3))
c<-array(NA,dim=c(2,4,3))

list<-list(a,b,c)

我想对所有数组求和以产生一个单个数组,该数组就是列表中所有数组的总和.

I would like to sum over all the arrays to produce a single array which is the sum of all in the list.

所以基本上是:a+b+c

有没有办法做到这一点?

Is there a way to do this?

我知道可以用矩阵来完成,但是我找不到数组的函数.

I know it can be done with matrices but I haven't been able to find a function for arrays.

推荐答案

您可以使用Reduce:

Reduce("+", list)

这篇关于对数组列表求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆