Square every element of v, without writing a loop
NumPy · from Vectorisation and ufuncs
elementwise opsnp.sqrtnp.wherenp.maximum+=out=Putting the kettle on…
Starting up…
Exercise 1
Square every element of v, without writing a loop.
your answer
stuck? the lesson behind it
Vectorisation and ufuncs
The loop doesn’t disappear — it moves somewhere much faster.