dooder
dooder

Reputation: 539

numpy 2 arrays added together resulting in same array but shifted

enter image description here

enter image description here

So I have data, in the form of 2 numpy arrays, that look like the above when plotted. For some reason, when I add the 2 numpy arrays together, element-wise as such:

c = a + b

and then plot c, I get this:

enter image description here

All I'm doing is 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? I'm really confused about this.

Upvotes: 0

Views: 39

Answers (3)

Frank Yellin
Frank Yellin

Reputation: 11330

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()

Upvotes: 0

Michael
Michael

Reputation: 2414

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. This will be more apparent if you plot c = 1000*a + b

Upvotes: 0

Quang Hoang
Quang Hoang

Reputation: 150825

You shouldn't. However, plot can be deceiving. a is almost constant: max changes is about 2e-3 compare to 0.7 in b.

Upvotes: 1

Related Questions