title: What is the fastest way to stack numpy arrays in a loop?
body: <p>I have a code that generates me within a <code>for</code> loop two numpy arrays (<code>data_transform</code>). In the first loop generates a numpy array of <code>(40, 2)</code> and in the second loop one of <code>(175, 2)</code>. I want to concatenate these two arrays into one, to give me an array of <code>(215, 2)</code>. I tried with <code>np.concatenate</code> and with <code>np.append</code>, but it gives me an error since the arrays must be the same size. Here is an example of how I am doing the code:</p>
  
  <pre><code>result_arr = np.array([])
  
  for label in labels_set:
      data = [index for index, value in enumerate(labels_list) if value == label]
      for i in data:
          sub_corpus.append(corpus[i])
      data_sub_tfidf = vec.fit_transform(sub_corpus) 
      data_transform = pca.fit_transform(data_sub_tfidf) 
      #Append array
      sub_corpus = []
  </code></pre>
  
  <p>I have also used <code>np.row_stack</code> but nothing else gives me a value of <code>(175, 2)</code> which is the second array I want to concatenate. </p>