11.1: Packages
Back in my day (circa 1990’s) when someone wanted to write a computer program, they wrote the entire thing themselves, line by line. Everything you needed to do – from something complex like making a remote network connection to something simple like computing the average of some numbers – was up to you to build. Code sharing over the Internet just wasn’t much of a thing.
Today, the reverse is true. When you write a complex data analysis program, most of the code will actually be written by others, if you do it right. This is because many, many smart people across the globe have written snippets of code to do all the common (and some not-so-common) things you’ll want to do, and your job is to string them all together. Put another way: you’re given most of the Legos ® – and even a bunch of pre-assembled chunks made with dozens of Legos ® each – and your job is to construct your masterpiece out of those building blocks.
In Python, a package is a repository of useful functions and methods that someone else has written. By import ing a package into your program, you’re making all those useful things available to you. Your own code can then call those functions/methods whenever you see fit. It’s the modular, organized, and elegant way to do things, in addition to saving a ton of time.
The first package we’ll use is called NumPy , which stands for “Numerical Python.” To import it, you should include this exact line of code in the first Code cell of your Notebook:
Code \(\PageIndex{1}\) (Python):
import numpy as np
Note that it’s in all lower-case letters. Once that cell has been executed, you now have access to all the NumPy “stuff,” which is the subject of this chapter.