Python - Lesson 3
Python - Lesson 3
02 04
Function Pandas
MODULE 3.
NUMPY
Module 3:NumPY
Introduction to NumPy
NumPy
• Introduces objects for multidimensional arrays and matrices, as well as functions that allow to
easily perform advanced mathematical and statistical operations on those objects
Quick start
Module 3: NumpY
Array shape
Module 3: NumpY
Array creation
Module 3: NumpY
Array creation
Module 3: NumpY
>>> a.dtype
dtype('int32')
>>> a[0,3:5]
array([3, 4])
0 1 2 3 4 5
>>> a[4:,4:]
array([[44, 45], 10 11 12 13 14 15
[54, 55]])
20 21 22 23 24 25
>>> a[:,2]
array([2,12,22,32,42,52]) 30 31 32 33 34 35
40 41 42 43 44 45
50 51 52 53 54 55
Module 3: NumpY
NumPy – Min/Max
MIN ARGMIN
NumPy – Min/Max
MAX ARGMAX
>>> a = array([1,2])
>>> b = array([3,4])
>>> a + b
array([4, 6])
Module 3: NumpY
>>> a = np.array([[1,2,3,4],[2,3,4,5]])
>>> b = np.array([[1,2,5,4],[1,3,4,5]])
>>> a == b
array([[True, True, False, True],
[False, True, True, True]])
# functional equivalent
>>> np.equal(a,b)
array([[True, True, False, True],
[False, True, True, True]])
Random with NumPy
Module 3: NumpY
NumPy – Random
np.random.randint(low, high=None, size=None, dtype=‘l’)
•Return random integers from low (inclusive) to high (exclusive)
Module 3: NumpY
NumPy – Random
np.random.random(size=None)
•Return random floats in the half-open interval [0.0, 1.0).
•size : int or tuple of ints, optional
Module 3: NumpY
NumPy – Random
numpy.random.choice(1-D-array, size=None, replace=True, p=None)
•Generates a random sample from a given 1-D array
•replace : boolean, optional (Whether the sample is with or without replacement)
Module 3: NumpY
NumPy – Random
np.random.shuffle(array)
• Modify a sequence in-place by shuffling its contents.
THANKS
CREDITS: This presentation template was created by
Slidesgo, including icons by Flaticon, and Name: Nguyễn Lê Chí Bảo
infographics & images by Freepik and illustrations Email: [email protected]
by Storyset Phone: 091 544 2420
Linkedin: nguyenlechibao