A431 of 56
0 XP
  1. Hook
  2. Problems

A4 · Problem set 7

Problem set 7: arrays

These labs use lessons 28 to 30: NumPy arrays, vectorized arithmetic and two-dimensional arrays. Each one replaces a loop over measurements with a few array operations. Write them without Python loops where you can; the hidden tests check the results, and the message says which case went wrong.

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 p=v2/R 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 12CV2 with C=τ/R.

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 R2/(R1+R2) with R1 down the rows and R2 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.

Have paper and a calculator ready. Work each problem out by hand, then enter the answer. Your first try on each one counts toward your score.

Practice

Keep practicing

7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.