简体   繁体   English

保存生成的numpy随机数组的顺序,而无需在python中使用列表?

[英]Saving the generated numpy random arrays in order without using lists in python?

I am trying to make couple of random arrays with numpy.random.poisson . 我正在尝试使用numpy.random.poisson制作几个随机数组。 I want to save each data sets in the order that they are generated. 我想按生成顺序保存每个数据集。 Now I am using list for doing that, I was wondering if there is a better way to do that which could have easy access to each set afterwards? 现在我正在使用列表来执行此操作,我想知道是否有更好的方法可以在以后轻松访问每个集合?

This is my code: 这是我的代码:

import numpy as np
data = np.random.randint(0, 255, (250, 250, 3)) 
total = np.zeros(data.shape)
listOfData = []
number = 10 #It could be any number
for i in range(number):
       new_total = np.random.poisson(lam=data)
       listOfData.append(new_total.flatten())
       total += new_total
firstSet = np.array(listOfData[0]).reshape(data.shape)

My data is a 3-D array. 我的数据是3-D数组。

在您的代码中, listOfData[0]已经是一个ndarray ,因此您可以跳过该部分。

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

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