我正在尝试创建一个函数来创建假数据,以便在单独的分析中使用。以下是对该功能的要求。在
问题1
在这个问题中,您将使用numpy创建假数据。在函数create_data下面的单元格中,有两个参数“n”和“rand_gen”“rand_gen”参数是一个伪随机数生成器。我们使用一个伪随机数生成器来产生相同的结果。在
使用numpy.random.randn函数来创建长度为n的numpy数组并返回该数组。在
这是我创建的函数。在def create_data(n, rand_gen):
'''
Creates a numpy array with n samples from the standard normal distribution
Parameters
-----------
n : integer for the number of samples to create
rand_gen : pseudo-random number generator from numpy
Returns
-------
numpy array from the standard normal distribution of size n
'''
numpy_array = np.random.randn(n)
return numpy_array
这是我对我的函数进行的第一个测试。
^{pr2}$
我需要这个精确的数组输出。[0.66698806, 0.02581308, -0.77761941, 0.94863382, 0.70167179,
-1.05108156, -0.36754812, -1.13745969, -1.32214752, 1.77225828]
我的输出仍然是完全随机的,我不完全理解RandomState调用试图用seed来创建上面的数组,而不是让它完全随机。我知道我需要在函数中使用rand_gen变量,但我不知道它在哪里,我想这是因为我不明白它在做什么。在