1/82
Comprehensive review flashcards covering core Python programming, NumPy array manipulations, SciPy optimization and signal processing functions, Pandas data processing methods, and Matplotlib plotting features.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Which Pandas DataFrame method keeps the first occurrence of duplicated emails and drops the rest while preserving original order?
df.drop_duplicates(subset='email', keep='first')
Which SciPy function samples n values from a normal distribution with mean μ and standard deviation σ?
scipy.stats.norm.rvs(loc=mu, scale=sigma, size=n, random_state=seed)
Which Pandas DataFrame method computes the correlation matrix specifically for numeric columns?
df.corr(numeric_only=True)
Which SciPy function is used to solve a linear system Ax=b for x?
scipy.linalg.solve(A, b)
What does the Python expression sum(1 for ch in "banana" if ch == 'a') return?
3
How is a Python function sqr(n) written to return the square of its numeric parameter n?
def sqr(n):
return n ** 2
Which SciPy function computes the one-sided Fast Fourier Transform (FFT) for real-valued input, returning non-negative frequency components only?
scipy.fft.rfft(x)
Which NumPy expression computes the dot product between two 1D arrays a and b?
np.dot(a, b) (or a @ b)
Which Python keyword creates a loop that iterates over items of an iterable?
for
Within a Matplotlib Figure, which component defines one plot area with its own x/y axes?
Axes
Given a sampled signal y(t) with sampling interval dt, which expression constructs frequency bins matching scipy.fft.fft?
f = scipy.fft.fftfreq(len(y), d=dt)
Which SciPy function computes the determinant of a square matrix A?
scipy.linalg.det(A)
Which Pandas method converts a DataFrame df to a NumPy array without including index or column headers?
df.to_numpy()
Which Python keyword is used to define a function?
def
How does boolean indexing with a 1D boolean mask behave when applied to a 2D array?
Using a 1D boolean mask of length equal to the number of rows selects rows where the mask value is True.
Which SciPy call performs a one-sample Kolmogorov-Smirnov (KS) test comparing sample x to a normal distribution N(μ,σ)?
stat, p = scipy.stats.ks_1samp(x, 'norm', mu, sigma)
Which SciPy function locates peaks in a 1D array y with optional prominence thresholds?
scipy.signal.find_peaks(y, prominence=1.0)
Which slicing syntax returns the first two rows of a 2D array A with shape (4,5)?
A[:2, :]
How does np.nan_to_num(x, nan=0.0, posinf=None, neginf=None) behave on array x?
It replaces NaN values with 0.0 and replaces positive/negative infinity with the maximum/minimum finite values representable by the array's data type.
What is the correct syntax for a simple Python lambda function that adds 1 to its input x?
lambda x: x + 1
Which Matplotlib function creates a bar chart from categories and values?
plt.bar(categories, values)
Which Python list comprehension removes all occurrences of value "V" from a list L?
[x for x in L if x != "V"]
Which Matplotlib function adds a legend for labeled plot elements?
plt.legend()
Which Matplotlib call creates a figure with a specific size of width 8inches and height 4inches?
plt.figure(figsize=(8, 4))
Given a = np.array([1, 2, 3]) and b = np.array([10, 20, 30]), what is the result of a + b in NumPy?
np.array([11, 22, 33])
Which Pandas call groups DataFrame df by column 'city' and computes the mean for numeric columns only?
df.groupby('city').mean(numeric_only=True)
In Matplotlib's object-oriented API, how do you create a Figure with two Axes stacked vertically and set a main figure title?
fig, (ax1, ax2) = plt.subplots(2, 1); fig.suptitle('Overview')
Which SciPy call detrends each column of a 2D array x by removing the mean along axis=0?
scipy.signal.detrend(x, axis=0, type='constant')
Which Pandas call replaces missing values (NaN) in column 'score' with the column mean?
df['score'].fillna(df['score'].mean())
Which Matplotlib function call creates a basic histogram of data with 20 bins?
plt.hist(data, bins=20)
Which Pandas expression returns the first 10 rows of DataFrame df without raising an error if df has fewer than 10 rows, while preserving the original index?
df.head(10)
Which SciPy function removes a linear trend from a signal y?
scipy.signal.detrend(y)
Which Python list method adds a single element to the end of a list?
append()
How is a Python variable name validated regarding keywords, hyphens, and starting characters?
A valid Python variable name must start with a letter or underscore, cannot contain hyphens (e.g., my-value), cannot start with digits (e.g., 2value), and cannot be a reserved keyword (e.g., class). For example, my_value is valid.
Which Matplotlib call creates a scatter plot with customized marker size set to 50?
plt.scatter(x, y, s=50)
How do you load MATLAB .mat data and compute photon energy E=λh⋅c using scipy.io and scipy.constants?
data = scipy.io.loadmat('exp.mat'); lam = data['lambda']; E = scipy.constants.h * scipy.constants.c / lam
Which Matplotlib call creates a histogram with custom bin edges and normalized density?
counts, edges, patches = ax.hist(data, bins=np.linspace(0, 1, 11), density=True)
Which NumPy call correctly samples 100 items from list cats with custom probabilities [0.5, 0.3, 0.2] with replacement?
np.random.choice(cats, size=100, p=[0.5, 0.3, 0.2], replace=True)
Which Pandas call reads a CSV file 'data.csv' into a DataFrame with column 'id' as the row index?
pd.read_csv('data.csv', index_col='id')
What is the output of list(zip([1, 2, 3], ['a', 'b'])) in Python?
[(1, 'a'), (2, 'b')]
Which SciPy function resamples a signal x to M samples using the Fourier method?
scipy.signal.resample(x, M)
Which Pandas call computes Pearson correlations among numeric columns, ignoring non-numeric dtypes, with pairwise complete observations?
df.corr(numeric_only=True, method='pearson')
What is the primary difference between Pandas .loc and .iloc indexers?
.loc selects data by label names, whereas .iloc selects data by integer position index.
Which SciPy function call solves an ordinary differential equation dtdy=f(y,t) given initial value y0 over time vector t?
scipy.integrate.odeint(f, y0, t)
Which SciPy function call designs a low-pass Butterworth filter of order N with normalized cutoff frequency Wn?
scipy.signal.butter(N, Wn, btype='low')
What is the output of print("Hello" + " " + "World") in Python?
Hello World
Which SciPy function computes the real cube root of each element in an array a?
scipy.special.cbrt(a)
Which Matplotlib function creates a 2×2 grid of subplots and returns the Figure and Axes array?
fig, axes = plt.subplots(2, 2)
Which Python code creates a 3D plot area and plots a surface Z=f(X,Y) using Matplotlib?
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z, cmap='viridis')
How do you save arrays a and b into 'data.npz' with explicit keyword names using NumPy?
np.savez('data.npz', features=a, labels=b)
Which built-in function opens a text file for reading by default in Python?
open("file.txt", "r") (or open("file.txt"))
Which Pandas call drops rows containing any missing (NaN) values from DataFrame df?
df.dropna(how='any')
What does np.reshape(np.arange(8), (2, 4)).ndim evaluate to?
2
Which Pandas expression correctly filters rows of DataFrame df where column 'age' is greater than 30?
df[df['age'] > 30]
Which SciPy function fits parameter values to experimental data (x,y) for a potentially non-linear model function func(x, *params)?
scipy.optimize.curve_fit(func, x, y)
Which Matplotlib functions add labels to the x-axis and y-axis of the current plot?
plt.xlabel('Time (s)'); plt.ylabel('Amplitude')
Which Matplotlib call creates subplots arranged in 2 rows and 1 column sharing the same x-axis?
fig, axes = plt.subplots(2, 1, sharex=True)
How do you create a single subplot at position row 2, column 3, index 4 using Matplotlib?
plt.subplot(2, 3, 4)
Which SciPy call finds the root of a non-linear scalar equation f(x)=0 near initial guess x0?
x_root = scipy.optimize.root(f, x0)
Which SciPy function assesses sample normality using skewness and kurtosis tests?
scipy.stats.normaltest(x)
Which SciPy function numerically integrates a callable function f(x) over interval [a,b]?
scipy.integrate.quad(f, a, b)
Which usage of to_numpy on a Pandas DataFrame preserves dtypes and avoids copying data when possible?
df.to_numpy(copy=False)
What is the output of print(type(3.0)) in Python?
<class 'float'>
What is the boolean result of bool(0) in Python?
False
Which Pandas expression filters DataFrame df for rows where column 'price' is between 10 and 20 inclusive?
df[df['price'].between(10, 20, inclusive='both')]
Which NumPy call creates a 3×3 array of ones with default data type float64?
np.ones((3, 3))
What is the default data type (dtype) of np.zeros((2, 3))?
float64
Which built-in function returns the total number of elements in a Python list?
len()
Which SciPy call minimizes a scalar objective function g(p) starting from parameter vector p0?
scipy.optimize.minimize(g, p0)
Which Pandas method prints concise summary information about a DataFrame, including data types and non-null counts?
df.info()
Which SciPy call performs 1D linear interpolation on data (x,y) with extrapolation enabled beyond the measured x-range?
f = scipy.interpolate.interp1d(x, y, kind='linear', fill_value='extrapolate'); y_new = f(x_new)
Which SciPy function loads MATLAB .mat files into Python dictionaries?
scipy.io.loadmat('data.mat')
Given a 2D NumPy array M, which call selects rows where the first column value is greater than 0?
M[M[:, 0] > 0]
Which Matplotlib function creates a line plot of y versus x using the stateful pyplot API?
plt.plot(x, y)
Which SciPy function applies a Gaussian blur to an image array img?
scipy.ndimage.gaussian_filter(img, sigma=1.0)
What is the kurtosis value for a normal distribution according to Fisher's definition in scipy.stats.describe?
0.0
Given a 2D NumPy array samples where each row represents filter transmittances for one run, how do you compute per-run total transmission using NumPy?
transmission = np.prod(samples, axis=1)
What indexing capabilities does a Pandas Series support regarding labels and positions?
A Pandas Series supports label-based indexing using strings and integer-position indexing using integer positions.
For noisy physics data (x,y), which SciPy call fits model y=a⋅ebx+c with error weights sigma and computes a realistic parameter covariance matrix?
params, cov = scipy.optimize.curve_fit(lambda x, a, b, c: a * np.exp(b * x) + c, x, y, sigma=sigma, absolute_sigma=True)
Which keyword argument in plt.plot controls the style of the line (such as dashed)?
linestyle
Which NumPy attribute or operation converts a 2D array A of shape (3,4) into its transpose of shape (4,3)?
A.T
Which Matplotlib plt.plot formatting string and argument draws a red dashed line with circle markers and assigns a legend label 'Series A'?
plt.plot(x, y, 'r--o', label='Series A')
Given x = np.arange(9).reshape(3, 3), which slicing expression produces a view rather than a copy?
x[:, 1:]