1/20
By the end of this section, students should be able to... • Create and manipulate Python lists and NumPy arrays • Understand the differences between lists and arrays • Apply indexing, slicing, and basic operations • Use NumPy for efficient, array-based numerical computation • Understand broadcasting for working with arrays of different shapes
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Emulating Arrays with Lists
Python lists can behave like arrays, but are less efficient and harder to manage in numerical work.
NumPy Array
A grid-like data structure that stores elements of the same type in an efficient format.
1D Array
A one-dimensional list of numbers, similar to a vector.
2D Array
A two-dimensional array, often visualized like a matrix (rows and columns)
Indexing (1D)
Accessing elements in a one-dimensional array using a[i]
where i
is the position.
Indexing (2D)
Accessing elements using a[i, j]
, where i
is the row index and j
is the column index.
Negative Indexing
Using negative numbers to count from the end (e.g., a[-1]
is the last element).
Slicing
Selecting a range of elements using a colon (e.g., a[1:3]
gives index 1 and 2, but not 3).
Colon Operator :
Represents a range or full row/column, similar to MATLAB.
Slicing (2D Arrays)
a[:,1]
selects a column; a[0,:]
selects a row.
Broadcasting
A NumPy feature that allows operations on arrays of different shapes by expanding dimensions where possible.
Vectorized Operation
Performing arithmetic across all array elements without using explicit loops.
Elementwise Operation
Each element of an array is operated on individually (e.g., a + b
adds corresponding elements).
No Dot Operator
Unlike MATLAB, NumPy does not need .*
or ./
for elementwise math.
Array Creation
Arrays can be created with functions like np.array()
, np.zeros()
, or np.arange()
.
Array Shape
Describes the dimensions and size of a NumPy array, indicating how many elements are in each dimension.
Array Consistency with MATLAB
NumPy indexing and slicing is conceptually similar to MATLAB, but uses square brackets.
Advantages of Arrays Over Lists
Arrays are more memory-efficient and faster for large numerical computations.
Dimensionality
Arrays can be extended beyond 2D to represent higher-dimensional data (e.g., time, layers).
Use of Arrays (in Engineering)
Arrays are ideal for simulations, signal processing, matrix algebra, and other engineering tasks.
Emulating Arrays with Lists
Python lists can behave like arrays, but are less efficient and harder to manage in numerical work.