朱莉娅矩阵的列的平均值
我有一个带有表单的浮点条目的大矩阵,
[ a b c d
e f g h
i j k l
m n o p ]
其中一些值是离群值,因此我想平均每个条目,其值及其在相应列中的近期k条目并保留形状。换句话说,对于k = 3:
[ a b c d
(e + a)/2 (f + b)/2 (g + c)/2 (h + d)/2
(e + a + i)/3 (f + b + j)/3 (g + c + k)/3 (h + d + l)/3
(e + i + m)/3 (f + j + n)/3 (g + k + o)/3 (h + l + p)/3 ]
etc.
I have a big matrix with float entries of the form
[ a b c d
e f g h
i j k l
m n o p ]
some of the values are outliers, so I wanted to average each of the entries with values with its recent k entries in the corresponding column and preserve the shape. In other words to have something like this for k = 3:
[ a b c d
(e + a)/2 (f + b)/2 (g + c)/2 (h + d)/2
(e + a + i)/3 (f + b + j)/3 (g + c + k)/3 (h + d + l)/3
(e + i + m)/3 (f + j + n)/3 (g + k + o)/3 (h + l + p)/3 ]
etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
rollingfunctions
和映射
:You can do this with
RollingFunctions
andmapslices
:我不知道
rollingfunctions
,但是常规循环速度更快4倍。我不确定这是否是由maplices
?测试产量:
I didn't know about
RollingFunctions
, but a regular loop is 4X faster. I'm not sure if it's some kind of type instability caused bymapslices
?.Testing yields: