I have a function:
import numpy as np, random
def simulation(low, high, num_pairs):
c = np.round(np.random.uniform(low, high, num_pairs), 2)
n = np.round((0.4*c-0.8), 2) # calculate rounded value
n = np.where(n < 0, 0, n) # if negative `n`, make zero, else `n`
return list(zip(c, n))
Calling this:
c_n_pairs = simulation(0, 15, 10)
print(*c_n_pairs, sep = "\n")
Outputs:
(5.69, 1.48)
(11.33, 3.73)
(7.16, 2.06)
(2.93, 0.37)
(8.47, 2.59)
(12.82, 4.33)
(12.84, 4.34)
(7.12, 2.05)
(7.11, 2.04)
(0.07, 0.0)
What I have works, but I'm wondering about the two n statements and if those can be consolidated into one.
n = np.round((0.4*c-0.8), 2) # calculate rounded value
n = np.where(n < 0, 0, n) # if negative `n`, make zero, else `n`