NumPy provides a wide range of mathematical operations that can be performed on arrays, making it a powerful tool for data manipulation and analysis. Let's explore some of the key mathematical operations supported by NumPy.
Element-Wise Operations: NumPy allows you to perform element-wise operations on arrays, which means that the operation is applied to each element individually. For example, you can add, subtract, multiply, or divide two arrays element-wise. Here's a simple example:
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
# Addition
c = a + b
print(c) # Output: [5 7 9]
# Subtraction
d = b - a
print(d) # Output: [3 3 3]
# Multiplication
e = a * b
print(e) # Output: [4 10 18]
# Division
f = b / a
print(f) # Output: [4. 2.5 2.]