Python Reading
Key Ideas
- NumPy is Python library written in C to provide fast numerical methods for scientific computation.
- NumPy enables Python users to use a data structure called an array. You can conceptualize an array as an efficient implementation of a list.
- Today we will learn about 1-D (one dimensional) arrays. However, Python arrays can contain any number of dimensions.
In-Class Activity
- One way to gain insight into numeric data is to calculate its mean and standard deviation. More information.
- Sometimes it is useful to sort numeric data into either ascending or descending order. Why?
- Download demo.py and conduct experiments until you fully understand it.
- Can you explain how the sort function works?
- The sort function does not return anything. Why does the shoulder_heights array in the main program change?
- Can you modify the sort function so that it sorts the data into descending order?
- The NumPy module includes a sort function. Can you find the relevant documentation and then use it?
- What are other useful things you might want to do with a 1-D array?
Active Learning
Installing Numpy (module only):
- Install NumPy on your machine:
- Windows: python -m pip install numpy
- Mac: pip3 install --user numpy
Installing Anaconda (recommended)
Anaconda is a Python distribution that already includes NumPy and many other useful libraries—so students usually don’t need to install anything extra.
Step 1: Download Anaconda
Go to: https://repo.anaconda.com/archive/
From there:
- Scroll to the version you want (usually the latest is fine)
- Download the installer directly:
- Run the installer normally
Step 2: Install Anaconda
Windows
-
- Double-click the downloaded installer
- Click Next → Agree → Next
- Choose Just Me (recommended)
- Leave settings as default
- Click Install
Mac
-
- Open the downloaded
.pkg file (easier to use than .sh)
- Click through the installer steps
- Install with default settings
Apple Silicon Macs (M1, M2, M3, etc.) Most newer Macs (≈ 2020+) Look for: arm64 or Apple Silicon
Intel Macs Older Macs (pre-2020) Look for: x86_64
Step 3: Open Anaconda Navigator
After installation:
- Open Anaconda Navigator (search for it like any app)
- This is your control panel for Python tools
Step 4: Launch Python
Launch:
- Jupyter Notebook, or
- JupyterLab, or
- Spyder (comes with Anaconda, similar to IDLE but more powerful)
Step 5: Test NumPy
In your notebook (or Spyder) type:
If you see:
NumPy is installed and working!
⚠️ Troubleshooting
“It won’t open”
- Restart your computer after installing
“Navigator is slow”
- Be patient on first launch—it can take a minute
“Still want to use IDLE?”
Anaconda uses its own Python. If students open IDLE from their system Python, NumPy might not be there.
👉 Best fix: Use Jupyter or Spyder instead.
Teacher, TA Tips
- This approach avoids most install problems from pip
- All students get the same environment
- Great for data science and future lessons