简体   繁体   English

在迭代中连接 numpy arrays

[英]Concatenate numpy arrays within for iterations

Within a for loop, I am extracting a Numpy array of size 10x256 .在 for 循环中,我正在提取大小为10x256的 Numpy 数组。 I would like to concatenate all those arrays (the iteration in total are 20) and create an array of size of 200x256 .我想连接所有这些 arrays (迭代总数为 20)并创建一个大小为200x256的数组。 I managed to do that by using a for loop within the for loop:我设法通过在 for 循环中使用 for 循环来做到这一点:

my_list= []
for i in range(0,20):
   my_arr = process() # 10x256
   for item in my_arr:
       my_list.append(item)

How can I do the same thing without using the second for loop?如何在不使用第二个 for 循环的情况下做同样的事情?

With single numpy.concatenate routine:使用单个numpy.concatenate例程:

new_arr = np.concatenate([process() for i in range(20)])

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

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