Q:

Write a NumPy program to calculate the difference between neighboring elements, element-wise of a given array

0

Write a NumPy program to calculate the difference between neighboring elements, element-wise of a given array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.array([1, 3, 5, 7, 0])
print("Original array: ")
print(x)
print("Difference between neighboring elements, element-wise of the said array.")
print(np.diff(x))

Sample Output:

Original array: 
[1 3 5 7 0]
Difference between neighboring elements, element-wise of the said array.
[ 2  2  2 -7]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now