title: Parse matrix from XML using Python
body: <p>Let's say I have a matrix stored in an XML-file in the following format:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  
  &lt;Matrix&gt;
      &lt;Value Col="0" Row="0"&gt;0.19343&lt;/Value&gt;
      &lt;Value Col="1" Row="0"&gt;0.95079&lt;/Value&gt;
      &lt;Value Col="2" Row="0"&gt;0.89542&lt;/Value&gt;
      &lt;Value Col="0" Row="1"&gt;0.14391&lt;/Value&gt;
      &lt;Value Col="1" Row="1"&gt;0.094629&lt;/Value&gt;
      &lt;Value Col="2" Row="1"&gt;0.52303&lt;/Value&gt;
  &lt;/Matrix&gt;
  </code></pre>
  
  <p>What is the best way to parse these values into a numpy array using xml.etree in Python <em>without knowing the size of the dimensions of the matrix</em>? Otherwise, I guess i could just simply do:</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  import numpy as np
  
  rowcnt = 2
  colcnt = 3
  
  xmltree = ET.parse('some_xmlfile.xml')
  matrix = np.zeros(shape=(rowcnt, colcnt))
  
  for m in xmltree.iter('Matrix'):
      for v in m.iter('Value'):
          col = int(v.attrib['Col'])
          row = int(v.attrib['Row'])
          matrix[row, col] = float(v.text)
      print matrix
  </code></pre>