Programming Part 3 Flashcards
(25 cards)
What is NumPy used for?
Efficient numerical computing with arrays.
What is the main data structure in NumPy?
The ndarray (n-dimensional array).
How do you import NumPy?
import numpy as np
How do you create a NumPy array from a list?
np.array([1, 2, 3])
How do you create an array of zeros?
np.zeros((rows, cols))
How do you get the shape of a NumPy array?
Using array.shape
How do you reshape an array?
Using array.reshape(new_shape)
What does np.arange() do?
Creates an array with regularly spaced values.
What does np.linspace() do?
Generates evenly spaced values over a specified range.
What is broadcasting in NumPy?
Automatic expansion of arrays with different shapes for element-wise operations.
How do you slice a NumPy array?
Using array[start:stop:step]
How do you index a 2D array?
Using array[row, column]
What is boolean indexing in NumPy?
Using a boolean array to filter values.
How do you access a single row in a 2D array?
Using array[row_index, :]
How do you access a single column in a 2D array?
Using array[:, col_index]
How do you compute the sum of an array?
Using np.sum(array)
How do you compute the mean of an array?
Using np.mean(array)
How do you compute the standard deviation?
Using np.std(array)
How do you find the max value in an array?
Using np.max(array)
How do you compute element-wise multiplication?
Using array1 * array2
How do you generate random numbers in NumPy?
Using np.random
How do you set the random seed in NumPy?
np.random.seed(42)
Why is NumPy faster than regular Python lists?
Because it uses fixed-typed, contiguous memory and vectorized operations.
What is vectorization?
Replacing explicit loops with array operations.