NumPy

Introducción a Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Resumen de listas

Potente

Conjunto de valores{2}

Contiene diferentes tipos{3}

Cambia, añade, elimina{4}

Necesidad de ciencia de datos{5}

Operaciones matemáticas sobre conjuntos{6}

Velocidad

Introducción a Python

Ilustración

"`py height = [1.73, 1.68, 1.71, 1.89, 1.79] height


```out
[1.73, 1.68, 1.71, 1.89, 1.79]
weight = [65.4, 59.2, 63.6, 88.4, 68.7]
weight
[65.4, 59.2, 63.6, 88.4, 68.7]
weight / height ** 2

out TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'{{3}}"

Introducción a Python

"Solución: NumPy"

"Python numérico{1}

Alternativa a la lista de Python: matriz de NumPy{2}

Cálculos sobre matrices completas{3}

Fácil y rápido{4}

Instalación{5} En el terminal: pip3 install numpy{6}"

Introducción a Python

NumPy

import numpy as np

np_height = np.array(height) np_height
array([1.73, 1.68, 1.71, 1.89, 1.79])
np_weight = np.array(weight)
np_weight
array([65.4, 59.2, 63.6, 88.4, 68.7])
bmi = np_weight / np_height ** 2
bmi
array([21.85171573, 20.97505669, 21.75028214, 24.7473475 , 21.44127836])
Introducción a Python

Comparación

"`py height = [1.73, 1.68, 1.71, 1.89, 1.79] weight = [65.4, 59.2, 63.6, 88.4, 68.7] weight / height ** 2


```out
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
np_height = np.array(height)
np_weight = np.array(weight)
np_weight / np_height ** 2

out array([21.85171573, 20.97505669, 21.75028214, 24.7473475 , 21.44127836]){{2}}"

Introducción a Python

"NumPy: observaciones"

"`py np.array([1.0, "is", True])


```out
array(['1.0', 'is', 'True'], dtype='<U32')

Matrices NumPy: contienen solo un tipo{1}"

Introducción a Python

"NumPy: observaciones"

"`py python_list = [1, 2, 3] numpy_array = np.array([1, 2, 3])


```py
python_list + python_list
[1, 2, 3, 1, 2, 3]
numpy_array + numpy_array
array([2, 4, 6])

Diferentes tipos: diferentes comportamientos{3}"

Introducción a Python

Subconjuntos de NumPy

bmi
array([21.85171573, 20.97505669, 21.75028214, 24.7473475 , 21.44127836])
bmi[1]
20.975
bmi > 23
array([False, False, False,  True, False])
bmi[bmi > 23]
array([24.7473475])
Introducción a Python

¡Vamos a practicar!

Introducción a Python

Preparing Video For Download...