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

ufunc Summations


Summations

What is the difference between summation and addition?

Addition is done between two arguments whereas summation happens over n elements.

Example

  import numpy as np

arr1 = np.array([1, 2, 3])
arr2 = np.array([1, 2,
  3])

newarr = np.add(arr1, arr2)

print(newarr)

Note: Returns: [2 4 6]

Example

  import numpy as np

arr1 = np.array([1, 2, 3])
arr2 = np.array([1, 2,
  3])

newarr = np.sum([arr1, arr2])

print(newarr)

Note: Returns: 12


Summation Over an Axis

If you specify axis=1, NumPy will sum the numbers in each array.

Example

  import numpy as np

arr1 = np.array([1, 2, 3])
arr2 = np.array([1, 2,
  3])

newarr = np.sum([arr1, arr2], axis=1)

print(newarr)

Note: Returns: [6 6]


Cummulative Sum

Cummulative sum means partially adding the elements in array.

E.g. The partial sum of [1, 2, 3, 4] would be [1, 1+2, 1+2+3, 1+2+3+4] = [1, 3, 6, 10].

Perfom partial sum with the cumsum() function.

Example

  import numpy as np

arr = np.array([1, 2, 3])

newarr = np.cumsum(arr)

print(newarr)

Note: Returns: [1 3 6]

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 Summations – FAQs

Quick answers about learning ufunc Summations in NumPy.

This free note from CodingNow 2.0 explains ufunc Summations 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 Summations, is 100% free with no signup required.
With focused practice, most students grasp ufunc Summations 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