Turn scores into bands with np.select: 3 for 80 and above, 2 for 60–79, 1 for 4…
NumPy · from where, select and clip
np.wherenp.selectnp.clipnp.nonzeroa[mask] = xnp.putmaskPutting the kettle on…
Starting up…
Exercise 4
Turn scores into bands with np.select: 3 for 80 and above, 2 for 60–79, 1 for 40–59, and 0 below that.
your answer
stuck? the lesson behind it
where, select and clip
An if-statement over a whole array, without losing its shape.