Challenge - Professor Prick¶
You’re a vindictive professor 👨🏫 and one of your pet peeves is when students rush through their exams. To teach them a lesson, you decide to give zeros to the first three students who score less than sixty, in the order they turned in their exams.
Given a 1-d array of integers, identify the first three values less than sixty and replace them with zero.
In [1]:
import numpy as np
generator = np.random.default_rng(80085)
scores = np.round(generator.uniform(low=30, high=100, size=15))
print(scores)
# [68. 36. 76. 57. 56. 54. 63. 64. 36. 88. 80. 82. 84. 76. 42.]
[68. 36. 76. 57. 56. 54. 63. 64. 36. 88. 80. 82. 84. 76. 42.]
In [7]:
less_than_60 = scores < 60
scores[less_than_60.nonzero()[0][:3]] = 0
scores
Out[7]:
array([68., 0., 76., 0., 0., 54., 63., 64., 36., 88., 80., 82., 84., 76., 42.])