</>
Skip to content
NumPy lessons (26/28)

NumPy — Mathematical Functions

where

import numpy as np

arr = np.array([1, 2, 3, 4, 5])
result = np.where(arr > 3, arr, 0)
print(result)  # [0, 0, 0, 4, 5]

unique

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

sort

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

concatenate

a = np.array([1, 2])
b = np.array([3, 4])
print(np.concatenate([a, b]))  # [1, 2, 3, 4]

stack

a = np.array([1, 2])
b = np.array([3, 4])
print(np.stack([a, b]))  # [[1, 2], [3, 4]]

split

arr = np.array([1, 2, 3, 4, 5, 6])
print(np.split(arr, 3))  # [[1, 2], [3, 4], [5, 6]]

clip

arr = np.array([1, 5, 10, 15, 20])
print(np.clip(arr, 5, 15))  # [5, 5, 10, 15, 15]

Mini Practice

  1. Use where for conditional
  2. Find unique values
  3. Sort arrays
  4. Concatenate and split

Up Next

Continue with Random - Random number generation.

Related Topics

Frequently Asked Questions about Mathematical Functions

What is Mathematical Functions in NumPy?

Mathematical Functions is a fundamental concept in NumPy. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Mathematical Functions?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Mathematical Functions.

Why is Mathematical Functions important in NumPy?

Mathematical Functions is essential for NumPy development. Understanding this concept will help you write better code and solve real-world problems more effectively.