Numerical computing with NumPy
You learn to process large sets of numbers quickly and compute simple statistics over event counts.
Level 201 · 17 lessons · 15 practice labs
Lessons
Arrays
- Why NumPy: lists versus arrays: You see the speed and memory difference between lists and NumPy arrays and know when to choose each.
- Creating arrays: array, zeros, arange, linspace: You build NumPy arrays from lists, zeros and ranges.
- Dimensions, shape and data type: You read an array’s dimensions, shape and type and see how type choice affects memory and overflow.
- Indexing and slicing: You pick a single element, a row, a column or a range out of an array.
- Quick task: turn event counts into an array
Calculations
- Vectorised operations and broadcasting: You compute over a whole array without loops and see how arrays of different sizes combine.
- Conditional selection with boolean masks: You select, count and change values above a threshold with a single expression.
- Aggregation, mean and the axis argument: You compute sums, means and standard deviations along rows or columns.
- Reshaping and combining arrays: You reshape arrays and join them vertically or side by side.
- Sorting, unique values and counting: You find unique values in an event record and count how often each appears.
- Percentiles and thresholds
- Quick task: hourly login statistics
Practice
- Random numbers and reproducibility: You make repeatable samples with a fixed seed and know this generator is unfit for passwords or keys.
- Loading and saving arrays: You write and read arrays as text and binary files and know the allow_pickle risk of untrusted files.
- Working with missing values: NaN
- A 2-D count table: IP by hour
- Capstone: spotting unusual hours with z-scores: You find hours that stray far from the average login count using z-scores and report them.
Practice labs
- From list to array: Convert sensor readings from a list into a NumPy array and print its shape, data type and memory use.
- An overflowing data type: Show why byte counters stored as int8 turned negative and recompute the total with the correct data type.
- Reshape a flat array into a day-hour table: Reshape a flat array of a month's hourly counts into a day×hour table and pad the incomplete last day correctly.
- Selecting a shift with slicing: Slice only the night-shift hours out of a day×hour array and compute their total event count.
- Threshold breaches with a boolean mask: Use a boolean mask to pull out the server-room readings above 75 degrees and their times.
- Combining several masks: Find with one combined mask the records that are at night, at the weekend and more than twice the average traffic and write their indexes.
- Unit conversion without a loop: Convert a traffic array from bytes to MB without a loop and print the five largest values.
- Normalising rows with broadcasting: Normalise each server's hourly load by its own mean using broadcasting and find the most volatile server.
- Vectorise a loop and time it: Vectorise a distance calculation written with nested loops and show that both versions agree and how much faster the new one is.
- Totals along an axis: Use the axis argument on a branch×month sales array to compute branch totals and month totals separately.
- Set a percentile threshold: Choose the 99th percentile of daily e-mails per user as a threshold and list the users who exceed it.
- Unique values and a count table: Use np.unique on IP and port arrays to count the most frequent IP-port pairs and print the top ten as a table.
- An average with NaN: Show the difference between np.mean and np.nanmean on an array with missing readings and write the correct average and the missing count.
- A reproducible random sample: Draw a 500-record sample from 10,000 with a fixed seed and prove two runs with the same seed give the same sample.
- Save, load and verify arrays: Save a computed count matrix as .npy and .npz, load it back and verify with a checksum that its summary is unchanged.
About this course
You learn to process large sets of numbers quickly and compute simple statistics over event counts.
What you will learn
- Arrays
- Calculations
- Practice
Prerequisites
Finishing the level 101 courses of the same path, or knowing those topics, is enough.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 201; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.