🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to NumPy Notes
Topic #39

ufunc Differences


Differences

A discrete difference means subtracting two successive elements.

E.g. for [1, 2, 3, 4], the discrete difference would be [2-1, 3-2, 4-3] = [1, 1, 1]

To find the discrete difference, use the diff() function.

Example

  import numpy as np

arr = np.array([10,
  15, 25, 5])

newarr = np.diff(arr)

print(newarr)

Note: Returns: [5 10 -20] because 15-10=5, 25-15=10, and 5-25=-20

We can perform this operation repeatedly by giving parameter n.

Example

  import numpy as np

arr = np.array([10,
  15, 25, 5])

newarr = np.diff(arr, n=2)

print(newarr)

Note: Returns: [5 -30] because: 15-10=5, 25-15=10, and 5-25=-20 AND 10-5=5 and -20-10=-30

Want to go beyond the notes?

Join CodingNow 2.0's NumPy course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

ufunc Differences – FAQs

Quick answers about learning ufunc Differences in NumPy.

This free note from CodingNow 2.0 explains ufunc Differences in NumPy — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every NumPy topic on CodingNow 2.0, including ufunc Differences, is 100% free with no signup required.
With focused practice, most students grasp ufunc Differences in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now