title: Building a small numpy array from individual values: Fast and readable method?
body: <p>I found that a bottleneck in my program is the creation of numpy arrays from a list of given values, most commonly putting four values into a 2x2 array. There is an obvious, easy-to-read way to do it:</p>
  
  <pre><code>my_array = numpy.array([[1, 3], [2.4, -1]])
  </code></pre>
  
  <p>which takes 15 us -- very very slow since I'm doing it millions of times.</p>
  
  <p>Then there is a far faster, hard-to-read way:</p>
  
  <pre><code>my_array = numpy.empty((2,2))
  my_array[0,0] = 1
  my_array[0,1] = 3
  my_array[1,0] = 2.4
  my_array[1,1] = -1
  </code></pre>
  
  <p>This is 10 times faster, at just 1 us.</p>
  
  <p>Is there any method that is BOTH fast AND easy-to-read?</p>
  
  <p>What I tried so far: Using <code>asarray</code> instead of <code>array</code> makes no difference; passing <code>dtype=float</code> into <code>array</code> also makes no difference. Finally, I understand that I can do it myself:</p>
  
  <pre><code>def make_array_from_list(the_list, num_rows, num_cols):
      the_array = np.empty((num_rows, num_cols))
      for i in range(num_rows):
          for j in range(num_cols):
              the_array[i,j] = the_list[i][j]
      return the_array
  </code></pre>
  
  <p>This will create the array in 4us, which is medium readability at medium speed (compared to the two approaches above). But really, I cannot believe that there is not a better approach using built-in methods.</p>
  
  <p>Thank you in advance!!</p>