I have the following question regarding using parenthesis when calling use defined function.
This is the code proposed by the book to simulate white noise process for 100 periods using User-Defined Function.
This is the code proposed by the book to simulate white noise process for 100 periods using User-Defined Function.
def generate_data(n, generator_type): ϵ_values = [] for i in range(n): e = generator_type() ϵ_values.append(e) return ϵ_values data = generate_data(100, np.random.uniform) plt.plot(data) plt.show()I am trying to change this code in the following way:
def generate_data(n, generator_type): ϵ_values = [] for i in range(n): e = generator_type ϵ_values.append(e) return ϵ_values data = generate_data(100, np.random.uniform()) plt.plot(data) plt.show()So, instead of having parenthesis inside the body of the function (e=generator_type()) I provide it as the name of the second variable in the function generate_data. But the code does not run in the second case. I wonder what is the difference and why it fails to provide the same results as the first version. The call should just take np.random.uniform() instead of generator_type and produce the same result should not it? Why should I put generator_type() parenthesis in the body and then put np.random.uniform as the variable? why does it make a difference where to put ()?