作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想对数组中的一维求和。这很容易。对于 9x100x100 阵列:
sum(a,1)
reshape(summed_array, 100,100)
最佳答案
更新
如 @E_net4在 a comment 中指出下面,从 Julia 1.0 开始,你应该使用 dropdims
(一个更好的名字!)而不是 squeeze
.
原答案
您正在寻找 squeeze
:
squeeze(A, dims)
Remove the dimensions specified by dims from array
A
. Elements ofdims
must be unique and within the range1:ndims(A)
.
julia> a = rand(4,3,2)
4x3x2 Array{Float64,3}:
[:, :, 1] =
0.333543 0.83446 0.659689
0.927134 0.885299 0.909313
0.183557 0.263095 0.741925
0.744499 0.509219 0.570718
[:, :, 2] =
0.967247 0.90947 0.715283
0.659315 0.667984 0.168867
0.120959 0.842117 0.217277
0.516499 0.60886 0.616639
julia> b = sum(a, 1)
1x3x2 Array{Float64,3}:
[:, :, 1] =
2.18873 2.49207 2.88165
[:, :, 2] =
2.26402 3.02843 1.71807
julia> c = squeeze(b, 1)
3x2 Array{Float64,2}:
2.18873 2.26402
2.49207 3.02843
2.88165 1.71807
关于arrays - 如何在删除遍历维度的同时对数组中的维度求和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38806584/
我是一名优秀的程序员,十分优秀!