简体   繁体   English

numpy 2个数组加在一起导致相同的数组但移位

[英]numpy 2 arrays added together resulting in same array but shifted

在此处输入图片说明

在此处输入图片说明

So I have data, in the form of 2 numpy arrays, that look like the above when plotted.所以我有 2 个 numpy 数组形式的数据,绘制时看起来像上面那样。 For some reason, when I add the 2 numpy arrays together, element-wise as such:出于某种原因,当我将 2 个 numpy 数组加在一起时,按元素如下:

c = a + b c = a + b

and then plot c, I get this:然后绘制c,我得到这个:

在此处输入图片说明

All I'm doing is plot.plot(c)我正在做的就是 plot.plot(c)

But that doesn't make sense right?但这没有意义吧? I shouldn't get the same exact plot as plot b (except shifted up) when adding those 2 together right?将这两个加在一起时,我不应该得到与图 b 完全相同的图(除了向上移动),对吗? I'm really confused about this.我真的很困惑。

You shouldn't.你不应该。 However, plot can be deceiving.然而,情节可能具有欺骗性。 a is almost constant: max changes is about 2e-3 compare to 0.7 in b . a几乎是恒定的:最大变化约为2e-3 ,而b0.7

a is practically a constant, the variations in a are much smaller than the variations in b so when you sum them together you only wind up seeing the variations in b on a plot. a实际上是一个常数, a中的变化比b的变化小得多,所以当你把它们加在一起时,你只能在图上看到b的变化。 This will be more apparent if you plot c = 1000*a + b如果您绘制c = 1000*a + b这将更加明显

I agree with all the other answers above.我同意上面的所有其他答案。 I think it will be much clearer to the original poster if they try drawing all three plots on the same graph, rather than showing each of them on a separate graph.我认为如果他们尝试在同一张图上绘制所有三个图,而不是在单独的图上显示它们中的每一个,那么原始海报会更清楚。

plt.plot(a)
plt.plot(b)
plt.plot(a + b)
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM