title: Read data from a txt file into 2D array python
body: <p>I'm fairly new to python and I would like to know if I could get some assistance with the problem I'm trying to solve:</p>
  
  <p>I would like to design a loop to iterate over every file in the directory and place the data into a 2D array for every file. I have a large directory of .txt files that contain 22 lines of 2 numbers per line.</p>
  
  <p>An example of how the files contents will be organized is:</p>
  
  <pre><code># Start of file_1.txt
  1 2
  3 4
  5 6
  7 8
  
  # Start of file 2.txt
  6 7
  8 9
  3 4
  5 5
  </code></pre>
  
  <p>I would like to read the data separated by whitespace into the first two reference locations in the array(i.e. <code>array = [x0][y0]</code>) , and at the newline, write the following data into the next location of the array (i.e. <code>array=[x1][y2]</code>). I see a lot of people saying to use <code>numpy</code>, <code>scipy</code>, and other methods but that is confusing me further.</p>
  
  <p>The output that I am seeking is:</p>
  
  <pre><code>[[1,2],[3,4],[5,6],[7,8], ...]
  </code></pre>
  
  <p>I'm bit stuck on how to iterate through the files in a directory and simultaneously place them into a 2D array. The code I have so far is:</p>
  
  <pre><code>import os
  trainDir = 'training/'
  testDir = 'testing/'
  array2D = []
  
  for filename in os.listdir(trainDir,testDir):
      if filename.endswith('.txt'):
          array2D.append(str(filename))
  
  print(array2D)
  </code></pre>
  
  <p>At the moment the above code does not work for two directories, but it does for one. Any help would be appreciated. </p>