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.
Getting Started
To install Anaconda
This includes Numpy and more data science modules we will also use later.
🐍 Installing NumPy with Anaconda (Mac & Windows)
>>>>>>>>These instructions were generated by ChatGPT. We can try this out together in class and see if there are problems.*
✅ Why use Anaconda?
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 the official website:
https://www.anaconda.com/download
- Download:
- Windows → 64-bit Graphical Installer
- Mac → Choose the correct version (Intel or Apple Silicon)
To NOT create an account...
✅ Easiest workaround (no account required)
Use the direct download page instead of the main landing page:
👉 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
This completely bypasses any login/signup prompt.
⚙️ 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
You have two easy options:
Option A (Recommended for beginners)
Launch:
- Jupyter Notebook
or
- JupyterLab
Click Launch, then open a new Python notebook.
Option B (If you want something like IDLE)
Launch:
- 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 already 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 Tips
- This approach avoids most install problems from pip
- All students get the same environment
- Great for data science and future lessons
* >>>>>>>> End of ChatGPT instructions
To install only Numpy:
- Install NumPy on your machine:
- Windows: python -m pip install numpy
- Mac: pip3 install --user numpy
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
Optional Alternative NumPy Installation for Windows Users
Enter the second instruction in the MS-DOS command prompt, from the same directory where the module was downloaded.
- Download numpy, choosing the version in the next instruction.
- python -m pip install numpy-1.13.3+mkl-cp36-cp36m-win32.whl