1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Main purpose of NumPy?
Efficient storage and computation with arrays/matrices
NumPy array vs. Python list?
NumPy array → regular structure/ same data type
Python list → can contain different data types
.shape vs .size vs .ndim?
shape → dimensions
size → total elements
nidim → number of dimensions
A NumPy array has 3 rows and 4 columns.
What are:
shape, size, nidm?
shape = (3, 4)
size= 12
nidim= 2
ROWS FIRST
what does:
[::-1]
do?
Reverses the array
What does:
[::2]
do?
Selects every second element, beginning at index 0
What does np.ones((2,3)) create?
A 2-row x 3-column array filled with 1.0
What does np.zeros((4,2)) create?
A 4-row x 2-column array filled with 0.0
What does:
np.linspace (start, stop, num)
do?
Creates num evenly spaced values from start through stop
Stop is included by default.
np.random.rand(5)
5 random floats in:
[0,1)
Argument order:
np.random.normal(…)
normal(mean, std, size)
Argument order:
np.random.randint(…)
randint(low, high, size)
integers in:
[low, high)
How does NumPy arithmetic normally operate?
ELEMENT-WISE
arr*2
→ multiply every element by 2
Given:
arr = np.array([2,5,8])
What is:
arr*3
[6 15 24]
What does np.mean(arr) calculate?
Arithmetic average.
ADD divide HOW MANY
What does np.median(arr) calculate?
The middle value after ordering.
Even number of values → average the two middle values
axis=0 vs axis=1?
axis=0 → COLUMNS
axis=1 → ROWS
For a 3×4 array, how many answers does:
np.mean(arr, axis=0)
return?
One mean for each COLUMN
What does:
arr > 10
return?
A Boolean array:
True/Fales
What does:
arr[arr > 10 ]
return?
The actual VALUES greater than 10.
Comparison → mask
Boolean indexing → values