Learn NumPy essentials for data analytics and scientific computing with hands-on examples.
NumPy is the fundamental package for scientific computing with Python. It provides support for large, multi-dimensional arrays and matrices, along with a collection of mathematical functions to operate on them.
import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr)
Create a simple NumPy array and print it.
NumPy allows you to perform element-wise operations on arrays, making mathematical computations efficient and concise.
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) # [ 4 10 18]
Element-wise addition and multiplication of NumPy arrays.
NumPy arrays can be sliced and indexed in powerful ways, similar to Python lists but with more features.
import numpy as np
arr = np.array([10, 20, 30, 40, 50])
print(arr[1:4]) # [20 30 40]
Slice a NumPy array to get a subarray.