" />
Menu
×
×
   ❮   
PYTHON FOR DJANGO DJANGO FOR BEGINNERS DJANGO SPECIFICS PAYMENT INTEGRATION API BASICS NUMPY FOR ML Roadmap
     ❯   

MATHEMATICAL OPERATIONS IN NUMPY

Advanced Mathematical Functions

×

Share this Topic

Share Via:

Thank you for sharing!


Summation & Cumulative Sum


# Summation of elements
import numpy as np

arr = np.array([1, 2, 3, 4])
print("Sum of elements:", np.sum(arr)) # 10

# Cumulative sum
print("Cumulative sum:", np.cumsum(arr)) # [1 3 6 10]

Finding Unique Elements & Counting Occurrences


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

# Finding unique elements and counting occurrences
unique_elements, counts = np.unique(arr, return_counts=True)
print("Unique elements:", unique_elements)
print("Counts:", counts)

Sorting an Array


arr = np.array([3, 1, 4, 1, 5, 9])

# Sorting the array
print("Sorted array:", np.sort(arr))

# Indices of sorted elements
print("Indices of sorted elements:", np.argsort(arr))

Finding Percentiles & Quantiles


data = np.array([10, 20, 30, 40, 50])

# Calculating percentiles
print("25th percentile:", np.percentile(data, 25))
print("50th percentile (median):", np.percentile(data, 50))
print("75th percentile:", np.percentile(data, 75))


Django-tutorial.dev is dedicated to providing beginner-friendly tutorials on Django development. Examples are simplified to enhance readability and ease of learning. Tutorials, references, and examples are continuously reviewed to ensure accuracy, but we cannot guarantee complete correctness of all content. By using Django-tutorial.dev, you agree to have read and accepted our terms of use , cookie policy and privacy policy.

© 2025 Django-tutorial.dev .All Rights Reserved.
Django-tutorial.dev is styled using Bootstrap 5.
And W3.CSS.