Numpy
Here are some tutorials and examples :
Before you start, It's important to import numpy in your code.
import numpy as npNumpy arrays
a = np.zeros(3)
# [0. 0. 0] ndarray with floats
a.shape
# (3,)
a.shape = (3, 1)
# [[0.
# 0.
# 0.]]
a = np.ones(5)
# [1. 1. 1. 1. 1.]
a = np.empty(3)
# [0. 0. 0]
a = np.linspace(2, 10, 5) # from 2 to 10, with 5 elements
# [2. 4. 6. 8. 10.]
a = np.array([1, 2, 3])
# [1, 2, 3] ndarray
a_list = [[10, 20, 30], [40, 50]]
a = np.array(a_list)
# [[10, 20, 30], [40, 50]] ndarray
np.random.seed(0)
a = np.random.randint(10, size=5)
# [5 0 3 3 7]
a[0:2]
# [5, 0]
a[-1]
# 7Statistical functions
Filters on arrays
Array Operations
Last updated
Was this helpful?