Python numpy.diff not giving negative numbers calculating acceleration?

557 Views Asked by At
import numpy as np

data = [128,64,32,16,8,4,2,1]
data = np.array(data, dtype=float)
velocity = np.diff(data)
acceleration = np.diff(velocity)

print(acceleration)

The above code gives me the following output:

[32. 16. 8. 4. 2. 1.]

These numbers should be NEGATIVE and I have no idea what's going on with numpy

Thank you!

1

There are 1 best solutions below

0
On

These numbers should be NEGATIVE and I have no idea what's going on with numpy.

This is not a problem with numpy. The velocity here is negative, but the acceleration is positive (since the velocity is increasing over time).