简体   繁体   English

尝试在Python 3.X中创建随机噪声样本的列表列表

[英]Trying to create a list of lists of a random noise sample in Python 3.X

I'm trying to create a list of a certain number of arrays, say 10, where each array is comprised of a number of random numbers between two values in a normal distribution. 我正在尝试创建一定数量的数组(例如10)的列表,其中每个数组由正态分布中两个值之间的多个随机数组成。 What I have so far is: 到目前为止,我有:

noise = abs(np.random.normal(0,0.1,20))
noise1 = []
for i in range(10):
    noise1 = noise.append(range(i,10))

Where 'noise' is an array of 20 random positive values between 0 and 0.1. 其中“噪声”是20个随机正值的数组,介于0和0.1之间。 Now I want to create a list of 10 of these arrays with different random numbers each time called 'noise1'. 现在,我想创建一个由10个具有不同随机数的数组组成的列表,每次称为“ noise1”。 Using this method I get the error 'TypeError: 'numpy.ndarray' object is not callable', meaning the program tries to use the array as a function, but I don't know how to solve the problem. 使用此方法,我得到错误“ TypeError:'numpy.ndarray'对象不可调用”,这意味着程序尝试将数组用作函数,但我不知道如何解决该问题。 Would really appreciate some help! 非常感谢您的帮助!

You need to use numpy.concatenate or numpy.append to append to a numpy array, which is why you are getting your current error. 您需要使用numpy.concatenatenumpy.append追加到numpy数组,这就是为什么出现当前错误的原因。 However, there is a much simpler way to create the list you desire. 但是,有一种更简单的方法来创建所需的列表。

noise1 = [abs(np.random.normal(0,0.1,20)) for _ in range(10)]
print(np.shape(noise1))

Output: 输出:

(10, 20)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM