title: How to reshape a text file in Python so that the rows/columns swap position?
body: <p>EDIT - SOLVED</p>
  
  <p>I have a text file which contains 100 rows of data, each with 500 columns of values. I need to simply swap these so that my file contains 500 rows of data and 100 columns of values.</p>
  
  <p>Everything in the first column <code>[:,0]</code> will be row #1, everything in the second column <code>[:,1]</code> will be row #2 - and so on until the end of the file.</p>
  
  <p>I have searched for solutions and stumbled across <code>np.reshape</code>, but for the life of me I haven't been able to find an example to use on an existing text file. I should mention I'm also not overly skilled with Python to figure this out on my own.</p>
  
  <hr>
  
  <p>Alternatively, here is the code I used to create this text file in the first place - if it is simpler to just fix something in here which will reshape it in the first place then I am open for suggestions.</p>
  
  <pre><code>diffs = []
  for number in range (1,101):
      filea = pl.loadtxt('file' + str(number) + 'a')
      fileb = pl.loadtxt('file' + str(number) + 'b')
      diff = fileb[:,1] - filea[:,1]
      diffs.append(diff)
      np.savetxt('diffs.txt', (diffs))
  </code></pre>
  
  <p>Here, I have 100 <code>a</code> files and 100 <code>b</code> files. They each contain 500 rows and 2 columns. I am finding the difference between the values in the second column for each and looking to get them all in a file which maintains the 500 rows, but instead has 100 columns with the diff for <code>1b-1a</code> <code>2b-2a</code> etc through to <code>100b-100a</code>.</p>
  
  <p>Hopefully I have explained myself in a way which can be understood. Thanks in advance for any help.</p>
  
  <hr>
  
  <p>SOLUTION: </p>
  
  <pre><code>reshape = np.loadtxt('diffs.txt')
  diffs2 = np.transpose(reshape)
  np.savetxt('diffs2.txt', (diffs2))
  </code></pre>