Aan de slagGa gratis aan de slag

Using Python packages

Python packages are sort of like the different Toolboxes in MATLAB; however, an important practical difference is that you don't always have access to them in your workspace. Instead, to use a Python package, you must import it explicitly.

You can import an entire package or just import a single function or module from a package. You can also alias a package name to something shorter on import.

# Import a package
import math

# Import a function from a package
from math import log

# Alias a package
import datetime as dt

Let's explore importing with the NumPy package, which lets you store and manipulate multi-dimensional arrays.

Deze oefening maakt deel uit van de cursus

Python for MATLAB Users

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import the NumPy package


# Print the value of pi from the NumPy package
print(____.____)
Code bewerken en uitvoeren