title: Python: Write array to file row by row
body: <p>I have a file with the content of</p>
  
  <pre><code>18
  21
  24
  27
  30
  </code></pre>
  
  <p>And  the array of </p>
  
  <pre><code>[[ 1  6 11]
   [ 2  7 12]
   [ 3  8 13]
   [ 4  9 14]
   [ 5 10 15]]
  </code></pre>
  
  <p>How can I write this array to file so that each row will be corresponding with the appropriate lines such as it becomes something like this:</p>
  
  <pre><code>18    1  6 11
  21    2  7 12
  24    3  8 13
  27    4  9 14
  30    5 10 15
  </code></pre>
  
  <p>I have used this code, but it does not write the code as I want. The code:</p>
  
  <pre><code>import numpy as np
  
      ourlist = []
      for i in range(1, 16):
          ourlist.append(i)
  
  
      mydata = np.matrix([ourlist])
      array_from_list=(mydata.reshape(3, 5))
      x_transpose = (np.transpose(array_from_list))   # the array above
  
      with open('5rows.txt','a') as f:                #the file containing numbers
       for elements in x_transpose:
           f.write(str(elements))
           f.write('\n')
  </code></pre>
  
  <p>It instead writes elements to the end of line. If possible, could you tell me how I can do this, please ? I really appreciate your help !</p>