Get Started:
reflection.md (tell us about yourself)hw1_exercises.pyBy completing this assignment, you will:
uvOpen reflection.md and answer the questions about your background and goals. This helps us understand where you’re coming from and tailor the course.
Questions:
We’ll use Visual Studio Code as our IDE with GitHub Copilot as your AI pair programmer. This mirrors how many professional developers work today.
Step 1: Install VS Code
Download and install Visual Studio Code for your operating system.
Step 2: Get GitHub Education Benefits
As a student, you get free access to GitHub Copilot and other developer tools:
Step 3: Install VS Code Extensions
Open VS Code and install these extensions (Ctrl/Cmd + Shift + X):
Step 4: Sign into GitHub Copilot
# function to calculate BMI and see if it suggests codeDeliverable: Screenshot showing VS Code with the Python and GitHub Copilot extensions installed and Copilot active.
A note on AI pair programming: Copilot is a tool to accelerate your work, not replace your learning. Use it to get unstuck, explore syntax, and see alternative approaches—but make sure you understand every line of code you submit. Your commit history should reflect your problem-solving process.
uv is a fast Python package and environment manager that we’ll use throughout the course. It’s written in Rust and is significantly faster than pip—it handles both virtual environment creation and package installation in one tool.
Install it by following the instructions for your operating system:
macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Verify the installation by running:
uv --version
Deliverable: Screenshot showing uv --version output.
You’ll create one shared Python environment for the entire course. This saves disk space (PyTorch is large!) and keeps things simple.
Step 1: Create your course folder and initialize the environment
macOS/Linux:
mkdir ~/MPHY6120
cd ~/MPHY6120
uv init
uv add torch numpy pandas matplotlib jupyter ipykernel
Windows (PowerShell):
mkdir ~\MPHY6120
cd ~\MPHY6120
uv init
uv add torch numpy pandas matplotlib jupyter ipykernel
This creates:
pyproject.toml — declares your dependenciesuv.lock — locks exact versions (reproducibility!).venv/ — virtual environment (shared by all homeworks)Step 2: Clone your homework INTO this folder
cd ~/MPHY6120
git clone <your-hw1-repo-url>
cd hw1-python-setup-<your-username>
Your folder structure should look like:
~/MPHY6120/
├── .venv/ ← shared environment
├── pyproject.toml
├── uv.lock
└── hw1-python-setup-<username>/ ← your homework repo
├── hw1_exercises.py
└── reflection.md
Note: If you have an NVIDIA GPU and want CUDA support, follow the PyTorch installation guide for your specific setup.
Step 3: Verify your installation
cd ~/MPHY6120
uv run python -c "import torch; import numpy; import pandas; print('All packages working!')"
Deliverable: Screenshot showing successful package imports.
Complete the following exercises in hw1_exercises.py from your cloned repository. The file contains function stubs—replace the None values with your implementations.
How to run your code:
Option 1: Using uv run (recommended)
From your course folder (~/MPHY6120), run:
cd ~/MPHY6120
uv run python hw1-python-setup-<your-username>/hw1_exercises.py
Or from inside your homework folder:
cd ~/MPHY6120/hw1-python-setup-<your-username>
uv run python hw1_exercises.py
uv run automatically finds the .venv in the parent folder.
Option 2: In VS Code
Since the .venv is in your course folder (not inside the homework), you need to point VS Code to it:
Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows) to open the Command Palette.venv folder (not the python binary inside it):
~/MPHY6120/.venv
F5Important: Enter the path to the
.venvfolder, not.venv/bin/python. VS Code needs the folder path to properly detect the environment.
Option 3: With venv activated manually
source ~/MPHY6120/.venv/bin/activate # Mac/Linux
# or: ~\MPHY6120\.venv\Scripts\activate # Windows
cd ~/MPHY6120/hw1-python-setup-<your-username>
python hw1_exercises.py
Array Creation (3 pts): Create a 1D NumPy array containing the integers 1 through 10.
Random Matrix (3 pts): Create a 3x3 matrix of random values between 0 and 1 using np.random.rand().
Statistics (3 pts): For your random matrix, compute and print the mean, standard deviation, min, and max.
Reshaping (3 pts): Create a 1D array of 12 elements and reshape it into a 3x4 matrix.
Slicing (3 pts): From your 3x3 random matrix, extract a 2x2 submatrix from the top-left corner.
Create DataFrame (3 pts): Create a DataFrame with columns patient_id, age, heart_rate, and diagnosis with at least 10 rows of sample data.
Add Column (3 pts): Add a new column age_group that categorizes patients as “young” (< 40), “middle” (40-65), or “senior” (> 65).
Filter (3 pts): Filter the DataFrame to show only patients with heart rate > 80.
GroupBy (3 pts): Group by diagnosis and compute the mean age and heart rate for each group.
Missing Data (3 pts): Introduce some NaN values into your DataFrame, then demonstrate using fillna() or dropna().
Create the following visualizations with proper labels, titles, and legends:
Line Plot (2.5 pts): Plot $y = x^2$ for $x \in [0, 10]$.
Scatter Plot (2.5 pts): Create a scatter plot of random (x, y) data with at least 50 points.
Histogram (2.5 pts): Generate 1000 samples from a normal distribution and plot a histogram.
Bar Chart (2.5 pts): Create a bar chart showing the count of patients per diagnosis from your DataFrame.
Continue working in hw1_exercises.py for these exercises.
From List (2 pts): Create a 2D tensor from a nested Python list.
torch.zeros(3, 4)torch.ones(2, 3)torch.rand(3, 3)torch.arange(0, 10, 2)dtype, shape, and device.Element-wise (3 pts): Create two 3x3 random tensors and perform element-wise addition, multiplication, and exponentiation.
Matrix Operations (4 pts): Perform matrix multiplication (@ or torch.matmul) and transpose.
NumPy Conversion (3 pts): Convert a PyTorch tensor to a NumPy array and back. Demonstrate that changes to one affect the other (shared memory).
Write code that:
Check Availability (4 pts): Check if CUDA is available and print the result.
GPU Info (3 pts): If CUDA is available, print the GPU device name. If not, print a message saying CPU will be used.
Device Transfer (3 pts): Create a tensor and move it to the available device (GPU if available, otherwise CPU). Print the tensor’s device.
# Example structure
import torch
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print(f"Using device: {device}")
if torch.cuda.is_available():
print(f"GPU: {torch.cuda.get_device_name(0)}")
x = torch.rand(3, 3).to(device)
print(f"Tensor device: {x.device}")
All submissions for this course are done through GitHub. This mirrors real-world software development workflows and helps you build essential version control skills.
hw1_exercises.py (replace None values with your code)git add hw1_exercises.py
git commit -m "Complete NumPy exercises 2.1.1-2.1.5"
git push
Good commit habits are part of your grade. We expect:
a]b3f2d1 Complete Part 3: PyTorch CUDA check
8c4e5f6 Add tensor operations and NumPy conversion
2d1a9b7 Complete Part 2: matplotlib visualizations
f7e8c3a Add pandas DataFrame exercises
9a2b4c5 Complete NumPy array operations
1e6d8f2 Verify environment setup - all packages installed
In the era of AI-assisted coding, your commit history tells the story of your work:
| Component | Points |
|---|---|
| Part 0: Reflection | 10 |
Completed reflection.md with thoughtful answers |
10 |
| Part 1: Environment Setup | 15 |
| VS Code + GitHub Copilot configured | 5 |
| uv and virtual environment set up | 5 |
| Packages installed correctly | 5 |
| Part 2: Python Skills | 40 |
| NumPy exercises | 15 |
| Pandas exercises | 15 |
| Matplotlib visualizations | 10 |
| Part 3: PyTorch Basics | 25 |
| Tensor creation | 8 |
| Tensor operations | 9 |
| GPU/CUDA check | 8 |
| Git Workflow | 10 |
| Multiple meaningful commits | 5 |
| Clear commit messages | 5 |
| Total | 100 |
Problem: You selected the interpreter but VS Code still uses the wrong Python.
Solution: When entering the interpreter path, enter the path to the .venv folder, not the python binary inside it:
Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows).venv folder (not .venv/bin/python):
~/MPHY6120/.venv
(base) and ignores your interpreterProblem: Conda’s base environment activates automatically and overrides your selection.
Solution: Disable conda auto-activation:
conda config --set auto_activate_base false
Then restart VS Code.
.venv folderProblem: The folder is hidden because it starts with a dot.
Solution:
Cmd+Shift+. to show hidden filesuv run command not foundProblem: uv isn’t in your PATH after installation.
Solution: Close and reopen your terminal, or run:
source ~/.bashrc # or ~/.zshrc on Mac