NumPy — Matrix Operations
Arithmetic
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
print(a + b) # [5, 7, 9]
print(a - b) # [-3, -3, -3]
print(a * b) # [4, 10, 18]
print(a / b) # [0.25, 0.4, 0.5]
print(a ** b) # [1, 32, 729]
Trigonometric
arr = np.array([0, np.pi/4, np.pi/2])
print(np.sin(arr))
print(np.cos(arr))
print(np.tan(arr))
Logarithmic
arr = np.array([1, 10, 100])
print(np.log(arr)) # Natural log
print(np.log10(arr)) # Base 10
print(np.log2(arr)) # Base 2
Exponential
arr = np.array([0, 1, 2, 3])
print(np.exp(arr))
print(np.exp2(arr))
Aggregations
arr = np.array([1, 2, 3, 4, 5])
print(np.sum(arr))
print(np.prod(arr))
print(np.cumsum(arr))
print(np.cumprod(arr))
Mini Practice
- Perform arithmetic
- Use trigonometric functions
- Calculate logarithms
- Practice aggregations
Up Next
Continue with Statistics - Statistical functions.
Related Topics
Frequently Asked Questions about Matrix Operations
What is Matrix Operations in NumPy?
Matrix Operations 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 Matrix Operations?
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 Matrix Operations.
Why is Matrix Operations important in NumPy?
Matrix Operations is essential for NumPy development. Understanding this concept will help you write better code and solve real-world problems more effectively.