Pakketten

Introductie tot Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Motivatie

  • Functies en methoden zijn super handig

  • Alle code in Python-distributie?

    • Enorme codebasis: rommelig

    • Veel code die je niet gaat gebruiken

    • Onderhoudsprobleem

Introductie tot Python

Pakketten

  • Overzicht van Python-scripts

  • Elk script = module

  • Specificeer functies, methoden en typen.

  • Duizenden pakketten beschikbaar

    • NumPy

    • Matplotlib

    • scikit-learn

Screenshot 2019-09-08 om 9.18.56 uur.png

Introductie tot Python

Pakket installeren

Introductie tot Python

Pakket importeren

import numpy

array([1, 2, 3])
NameError: name 'array' is not defined
numpy.array([1, 2, 3])
array([1, 2, 3])
import numpy as np

np.array([1, 2, 3])
array([1, 2, 3])
from numpy import array

array([1, 2, 3])
array([1, 2, 3])
Introductie tot Python

from numpy import array

  • my_script.py
from numpy import array

fam = ["liz", 1.73, "emma", 1.68, "mom", 1.71, "dad", 1.89] ...
fam_ext = fam + ["me", 1.79] ...
print(str(len(fam_ext)) + " elements in fam_ext") ...
np_fam = array(fam_ext)
  • NumPy gebruiken, maar het is niet zo duidelijk
Introductie tot Python

import numpy

import numpy as np

fam = ["liz", 1.73, "emma", 1.68, 
    "mom", 1.71, "dad", 1.89]

...

fam_ext = fam + ["me", 1.79] ...
print(str(len(fam_ext)) + " elements in fam_ext") ...
np_fam = np.array(fam_ext) # Clearly using NumPy
Introductie tot Python

Laten we oefenen!

Introductie tot Python

Preparing Video For Download...