Python - Create a condition to obtain the odd multiples of 5 from the data array


Team,
Can you help with below?, I tried but unable to get the correct code

Thanks
Viren

Python
Create a condition to obtain the odd multiples of 5 from the data array.
This time, you won't be using the numpy.where method. You can directly insert the necessary conditions. The previous numpy method needed output for its condition if True or False. This time you might not need it.
The data variable is a Numpy array whose elements are randomly sampled from a uniform distribution of integers from 100 (inclusive) to 200 (exclusive).
Instructions
In the condition variable, specify the two necessary sub-conditions that must be met in order to have the odd multiples of 5. Example: From 1 to 20, the odd multiples of 5 are 5 and 15.

Hi Viren,



The condition can be:

condition = (data % 5 == 0) & (data % 2 != 0)
odd_multiples_of_5 = data[condition]

Hope this helps!

Thanks Akshay,

Have two questions:

  1. Why data%2
  2. It talks about integers from 100 (inclusive) to 200 (exclusive). We are not incorporating this in the code. How will this requirement be met?



     

Hi Viren,

  1. (data%2 != 0) is done to make sure that we only include the odd multiples of 5
  2. You can generate the random numbers using the following code:
data = np.random.randint(100, 200, size=100)

Thanks Akshay,