矩阵加法跳过 NaN 值
我想对矩阵进行元素明智加法,同时跳过 NaN 值。 MATLAB 和 Octave 有 nansum,但它在矩阵内进行按列加法。
让:
a = NaN * zeros(3)
b = ones(3)
我想要:
c = nan+(a, b)
和
c = b
和:
d = nan+(a,a)
和
d = a
I would like to do element wise addition over matrices while skipping NaN values.
MATLAB and Octave have nansum, but it does column wise addition within a matrix.
Let:
a = NaN * zeros(3)
b = ones(3)
I want:
c = nan+(a, b)
and
c = b
and:
d = nan+(a,a)
and
d = a
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您沿第 n+1 维串联 nd 数组,您仍然可以使用 nansum。
对于 2D
一般情况
You can still use nansum, if you catenate your n-d arrays along the n+1st dimension.
For 2D
The general case