title: Using numpy's genfromtxt to load a triangular matrix with python
body: <p>I have a text file containing an upper 'triangular' matrix, the lower values being omitted (here's an example below):</p>
  
  <blockquote>
    <p>3 5   3   5   1   8   1   6   5   8</p>
    
    <p>5 8   1   1   6   2   9   6   4</p>
    
    <p>2 0   5   2   1   0   0   3</p>
    
    <p>2 2   5   1   0   1   0</p>
    
    <p>1 3   6   3   6   1</p>
    
    <p>4 2   4   3   7</p>
    
    <p>4 0   0   1</p>
    
    <p>0 1   8</p>
    
    <p>2 1</p>
    
    <p>1</p>
  </blockquote>
  
  <p>Since the file in question is ~10000 lines in size, I was wondering if there was a 'smart' way to generate a <code>numpy</code> matrix from it e.g. using the <code>genfromtxt</code> function. However using it directly throws an error on the lines of
  <code>Line #12431 (got 6 columns instead of 12437)</code> and using <code>filling_values</code> won't work as there's no way to designate the no missing value placeholders.</p>
  
  <p>Right now I have to resort to manually open and close the file:</p>
  
  <pre><code>import numpy as np
  def load_updiag(filename, size):
      output = np.zeros((size,size))
      line_count = 0
      for line in f:
          data = line.split()
          output[line_count,line_count:size]= data
          line_count += 1
      return output
  </code></pre>
  
  <p>Which I feel is probably not very scalable for large file sizes.
  Is there a way to properly use <code>genfromtxt</code> (or any other optimized function from numpy's library) on such matrices?</p>