数组平均值矩阵 [英] Matrix of averages from array

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

问题描述

现在我有一个三维数组.我在第三维中有200行,200列和24个切片"

Right now i have an array that is three dimensions. I have 200 rows, 200 columns and 24 "slices" in the third dimension

dim=c(200,200,24)

我需要的是产生新矩阵的切片的平均值.我需要一个200 x 200的矩阵,其值是对相应切片进行平均后得到的结果.因此,在第1行第1行的位置,我需要我数组中所有第1行和第1行的平均值.

What I need is an average of the slices resulting in a new matrix. I need a 200 by 200 matrix and the values are the result of averaging up the appropriate slices. So in the location that would be row 1, col 1, I need the average of all the row 1's and col 1's from my array.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

以下是一个使用简单示例的尝试:

Here's one attempt using a simple example:

test <- 1:8
dim(test) <- c(2,2,2)

, , 1

     [,1] [,2]
[1,]    1    3
[2,]    2    4

, , 2

     [,1] [,2]
[1,]    5    7
[2,]    6    8

获得答案:

apply(test,c(1,2),mean)

     [,1] [,2]
[1,]    3    5
[2,]    4    6

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

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