NumPy arrays
Not met yet
np.array() turns a list of numbers into an array: a block of numbers of one type, stored side by side. An array has a shape, the number of items along each axis, so 395 students with three marks each is (395, 3). marks[3, 2] is row 3, column 2, and marks[:, 0] is every row of column 0. Methods like sum and mean take axis=, and the axis you name is the one that collapses.
Try it
main.pyOutput
Press Run and what your program prints shows up here.
Easy to get wrong
- Thinks multiplying a list by a number multiplies each item, rather than repeating the list.
- Thinks a NumPy array behaves like a list, so * repeats it and + joins two arrays end to end.
- Thinks axis=0 keeps one result per row. The axis named is the one that is collapsed, so axis=0 gives one result per column.
Where it comes up
- NumPy Grade Book
- Census Explorer
- Weather History Dashboard
- Statistics Toolkit
- Linear Algebra Lab
- Calculus for ML
- Data Story
- House Price Predictor
- Exam Score Model
- Diabetes Risk Classifier
- Iris and Penguins Classifier
- Loan Approval Tree
- Customer Segmentation
- Model Evaluation Clinic
- Neural Network from Scratch
- Optimiser Benchmark
- Handwritten Digit Recogniser
- Image Classifier
- Seeing Forecaster
- Tide Predictor
- Text Generator
- Tiny GPT
- A/B Test Bandit
- Gridworld Simulator
- Value Estimator
- Q-Learning Crab
- Tide Gate Controller
- CartPole with DQN
- Policy Gradients
- Actor-Critic and PPO
- Arcade League
- Paper Reproduction
- Radio Station Finder