Back to NUMPY FOUNDATIONS

NumPy Basics

Learn how to create, index, slice, and manipulate NumPy arrays for fast numerical operations.

14 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. NumPy Importance — NumPy is introduced as the essential, fast library for numerical Python used in data science and machine learning.
  2. Basic Array Creation — The lesson demonstrates creating arrays filled with zeros and ones, noting that they default to float data types.
  3. Linspace and Conversion — Arrays are created using `np.linspace` for evenly spaced values and `np.array` to convert existing Python lists.
  4. Array Attributes and Help — The shape attribute is shown, along with tips for using the Tab key and question mark in Jupyter notebooks for help.
  5. 1D Indexing and Slicing — Basic indexing and slicing techniques are demonstrated, including using negative indices to access the last element.
  6. Advanced 2D Slicing — Slicing is applied to a 2D image array to reverse rows, reverse columns, and extract specific sections of the data.
  7. Universal Functions (UFuncs) — Mathematical functions like sine are applied element-wise across the entire array using broadcasting without loops.
  8. Aggregation Methods — Common statistical methods are shown, including sum, mean, standard deviation, and finding the index of the minimum and maximum values.
  9. Boolean Masking — Boolean masks are used to filter array elements based on a condition and to conditionally replace values using `np.where`.
  10. Arithmetic and Transpose — Element-wise array arithmetic, the dot product (`@`), the transpose operation (`.T`), and array sorting are demonstrated.
PDF notes

Frequently asked questions

Why is NumPy faster than standard Python lists?

NumPy arrays store data contiguously in memory and operations are executed using highly optimized C code, avoiding Python interpreter overhead.

What is broadcasting?

Broadcasting is the mechanism that allows NumPy to perform operations on arrays of different shapes, typically by stretching a smaller array (like a scalar) to match the larger array's dimensions.

How do I find documentation for a function in Jupyter?

Type the function name followed by a question mark (e.g., `np.array?`) and execute the cell to view the docstring and parameters.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.