A4 Python for engineers · Practice
Problem set 7: arrays
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
The starter has an array R of resistor values in ohms. Each sits alone across V = 5 V. Set P to the array of their powers, total to the total power, and worst to the index of the resistor that dissipates the most, without loops.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes noisy samples v. Using a Boolean mask, set frac to the fraction of samples above th = 1 V, mean_above to the average of just those samples, and n_neg to how many are negative.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor discharges into a 10 Ω resistor from 10 V with time constant tau = 2 ms. The starter samples the power every 10 µs for 10 time constants. Set E to the energy delivered, by the trapezoid rule written with array slices (no np.trapz), and exact to with .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A thermal camera's image of a board is the 2-D array T in °C (made in the starter). Set hot to the (row, col) of the hottest pixel using np.argmax and np.unravel_index, row_means to the mean of each row, and over to how many pixels in row r = 2 exceed 60 °C.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using broadcasting, build ratio, a table of with down the rows and across the columns, both from the starter's E12 list (1 kΩ to 8.2 kΩ). Set n_good to how many pairs land within 1% of the target k = 0.4, and best to the (R1, R2) pair closest to it.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A sine of amplitude A = 6 V goes through a clipper that limits it to ±L = 2.5 V. Using np.where (or np.clip), set out to the clipped samples, n_clipped to how many samples were changed, and rms_out to the RMS of the output.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A logic signal is sampled every microsecond. Threshold it at th = 1.65 V into 0s and 1s, then use np.diff to set rises to the sample indices where it goes from 0 to 1 (the index of the first 1), and width to the average number of samples each high pulse lasts.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in A4