Data Modeling and Scientific Computing with Python

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/82

flashcard set

Earn XP

Description and Tags

Comprehensive review flashcards covering core Python programming, NumPy array manipulations, SciPy optimization and signal processing functions, Pandas data processing methods, and Matplotlib plotting features.

Last updated 10:22 AM on 9/8/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

83 Terms

1
New cards

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')

2
New cards

Which SciPy function samples nn values from a normal distribution with mean μ\mu and standard deviation σ\sigma?

scipy.stats.norm.rvs(loc=mu, scale=sigma, size=n, random_state=seed)

3
New cards

Which Pandas DataFrame method computes the correlation matrix specifically for numeric columns?

df.corr(numeric_only=True)

4
New cards

Which SciPy function is used to solve a linear system Ax=bAx = b for xx?

scipy.linalg.solve(A, b)

5
New cards

What does the Python expression sum(1 for ch in "banana" if ch == 'a') return?

3

6
New cards

How is a Python function sqr(n) written to return the square of its numeric parameter nn?

def sqr(n):
    return n ** 2
7
New cards

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)

8
New cards

Which NumPy expression computes the dot product between two 1D arrays a and b?

np.dot(a, b) (or a @ b)

9
New cards

Which Python keyword creates a loop that iterates over items of an iterable?

for

10
New cards

Within a Matplotlib Figure, which component defines one plot area with its own x/y axes?

Axes

11
New cards

Given a sampled signal y(t)y(t) with sampling interval dtdt, which expression constructs frequency bins matching scipy.fft.fft?

f = scipy.fft.fftfreq(len(y), d=dt)

12
New cards

Which SciPy function computes the determinant of a square matrix AA?

scipy.linalg.det(A)

13
New cards

Which Pandas method converts a DataFrame df to a NumPy array without including index or column headers?

df.to_numpy()

14
New cards

Which Python keyword is used to define a function?

def

15
New cards

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.

16
New cards

Which SciPy call performs a one-sample Kolmogorov-Smirnov (KS) test comparing sample x to a normal distribution N(μ,σ)N(\mu, \sigma)?

stat, p = scipy.stats.ks_1samp(x, 'norm', mu, sigma)

17
New cards

Which SciPy function locates peaks in a 1D array y with optional prominence thresholds?

scipy.signal.find_peaks(y, prominence=1.0)

18
New cards

Which slicing syntax returns the first two rows of a 2D array A with shape (4,5)(4, 5)?

A[:2, :]

19
New cards

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.

20
New cards

What is the correct syntax for a simple Python lambda function that adds 11 to its input xx?

lambda x: x + 1

21
New cards

Which Matplotlib function creates a bar chart from categories and values?

plt.bar(categories, values)

22
New cards

Which Python list comprehension removes all occurrences of value "V" from a list L?

[x for x in L if x != "V"]

23
New cards

Which Matplotlib function adds a legend for labeled plot elements?

plt.legend()

24
New cards

Which Matplotlib call creates a figure with a specific size of width 8inches8\,\text{inches} and height 4inches4\,\text{inches}?

plt.figure(figsize=(8, 4))

25
New cards

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])

26
New cards

Which Pandas call groups DataFrame df by column 'city' and computes the mean for numeric columns only?

df.groupby('city').mean(numeric_only=True)

27
New cards

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')

28
New cards

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')

29
New cards

Which Pandas call replaces missing values (NaN) in column 'score' with the column mean?

df['score'].fillna(df['score'].mean())

30
New cards

Which Matplotlib function call creates a basic histogram of data with 2020 bins?

plt.hist(data, bins=20)

31
New cards

Which Pandas expression returns the first 1010 rows of DataFrame df without raising an error if df has fewer than 1010 rows, while preserving the original index?

df.head(10)

32
New cards

Which SciPy function removes a linear trend from a signal y?

scipy.signal.detrend(y)

33
New cards

Which Python list method adds a single element to the end of a list?

append()

34
New cards

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.

35
New cards

Which Matplotlib call creates a scatter plot with customized marker size set to 5050?

plt.scatter(x, y, s=50)

36
New cards

How do you load MATLAB .mat data and compute photon energy E=hcλE = \frac{h \cdot c}{\lambda} using scipy.io and scipy.constants?

data = scipy.io.loadmat('exp.mat'); lam = data['lambda']; E = scipy.constants.h * scipy.constants.c / lam

37
New cards

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)

38
New cards

Which NumPy call correctly samples 100100 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)

39
New cards

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')

40
New cards

What is the output of list(zip([1, 2, 3], ['a', 'b'])) in Python?

[(1, 'a'), (2, 'b')]

41
New cards

Which SciPy function resamples a signal x to MM samples using the Fourier method?

scipy.signal.resample(x, M)

42
New cards

Which Pandas call computes Pearson correlations among numeric columns, ignoring non-numeric dtypes, with pairwise complete observations?

df.corr(numeric_only=True, method='pearson')

43
New cards

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.

44
New cards

Which SciPy function call solves an ordinary differential equation dydt=f(y,t)\frac{dy}{dt} = f(y, t) given initial value y0y_0 over time vector tt?

scipy.integrate.odeint(f, y0, t)

45
New cards

Which SciPy function call designs a low-pass Butterworth filter of order NN with normalized cutoff frequency WnW_n?

scipy.signal.butter(N, Wn, btype='low')

46
New cards

What is the output of print("Hello" + " " + "World") in Python?

Hello World

47
New cards

Which SciPy function computes the real cube root of each element in an array a?

scipy.special.cbrt(a)

48
New cards

Which Matplotlib function creates a 2×22 \times 2 grid of subplots and returns the Figure and Axes array?

fig, axes = plt.subplots(2, 2)

49
New cards

Which Python code creates a 3D plot area and plots a surface Z=f(X,Y)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')
50
New cards

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)

51
New cards

Which built-in function opens a text file for reading by default in Python?

open("file.txt", "r") (or open("file.txt"))

52
New cards

Which Pandas call drops rows containing any missing (NaN) values from DataFrame df?

df.dropna(how='any')

53
New cards

What does np.reshape(np.arange(8), (2, 4)).ndim evaluate to?

2

54
New cards

Which Pandas expression correctly filters rows of DataFrame df where column 'age' is greater than 3030?

df[df['age'] > 30]

55
New cards

Which SciPy function fits parameter values to experimental data (x,y)(x, y) for a potentially non-linear model function func(x, *params)?

scipy.optimize.curve_fit(func, x, y)

56
New cards

Which Matplotlib functions add labels to the x-axis and y-axis of the current plot?

plt.xlabel('Time (s)'); plt.ylabel('Amplitude')

57
New cards

Which Matplotlib call creates subplots arranged in 22 rows and 11 column sharing the same x-axis?

fig, axes = plt.subplots(2, 1, sharex=True)

58
New cards

How do you create a single subplot at position row 22, column 33, index 44 using Matplotlib?

plt.subplot(2, 3, 4)

59
New cards

Which SciPy call finds the root of a non-linear scalar equation f(x)=0f(x) = 0 near initial guess x0x_0?

x_root = scipy.optimize.root(f, x0)

60
New cards

Which SciPy function assesses sample normality using skewness and kurtosis tests?

scipy.stats.normaltest(x)

61
New cards

Which SciPy function numerically integrates a callable function f(x)f(x) over interval [a,b][a, b]?

scipy.integrate.quad(f, a, b)

62
New cards

Which usage of to_numpy on a Pandas DataFrame preserves dtypes and avoids copying data when possible?

df.to_numpy(copy=False)

63
New cards

What is the output of print(type(3.0)) in Python?

<class 'float'>

64
New cards

What is the boolean result of bool(0) in Python?

False

65
New cards

Which Pandas expression filters DataFrame df for rows where column 'price' is between 1010 and 2020 inclusive?

df[df['price'].between(10, 20, inclusive='both')]

66
New cards

Which NumPy call creates a 3×33 \times 3 array of ones with default data type float64?

np.ones((3, 3))

67
New cards

What is the default data type (dtype) of np.zeros((2, 3))?

float64

68
New cards

Which built-in function returns the total number of elements in a Python list?

len()

69
New cards

Which SciPy call minimizes a scalar objective function g(p)g(p) starting from parameter vector p0p_0?

scipy.optimize.minimize(g, p0)

70
New cards

Which Pandas method prints concise summary information about a DataFrame, including data types and non-null counts?

df.info()

71
New cards

Which SciPy call performs 1D linear interpolation on data (x,y)(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)

72
New cards

Which SciPy function loads MATLAB .mat files into Python dictionaries?

scipy.io.loadmat('data.mat')

73
New cards

Given a 2D NumPy array M, which call selects rows where the first column value is greater than 00?

M[M[:, 0] > 0]

74
New cards

Which Matplotlib function creates a line plot of yy versus xx using the stateful pyplot API?

plt.plot(x, y)

75
New cards

Which SciPy function applies a Gaussian blur to an image array img?

scipy.ndimage.gaussian_filter(img, sigma=1.0)

76
New cards

What is the kurtosis value for a normal distribution according to Fisher's definition in scipy.stats.describe?

0.0

77
New cards

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)

78
New cards

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.

79
New cards

For noisy physics data (x,y)(x, y), which SciPy call fits model y=aebx+cy = a \cdot e^{b x} + 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)

80
New cards

Which keyword argument in plt.plot controls the style of the line (such as dashed)?

linestyle

81
New cards

Which NumPy attribute or operation converts a 2D array A of shape (3,4)(3, 4) into its transpose of shape (4,3)(4, 3)?

A.T

82
New cards

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')

83
New cards

Given x = np.arange(9).reshape(3, 3), which slicing expression produces a view rather than a copy?

x[:, 1:]