title: Fill a Pytables array with random values: horizontally vs vertically
body: <p>So I am using Pytables to store a numpy array of size <code>(10,000 x 100)</code>. My goal is to fill it with random values.</p>
  
  <pre><code>import tables as tb
  h5File = '/Users/me/tmp0/test0.h5'
  f = tb.openFile( h5File, 'w')
  atom = tb.Atom.from_dtype( numpy.dtype('Float32'))
  x = f.createCArray( f.root, 'prices', atom=atom, shape=(10000, 100) )
  </code></pre>
  
  <p>In this example I could simply do <code>x[:]=nr.random(10000,100)</code>, but in reality my matrix is much bigger, more like <code>(100,000,000 x 500)</code>. So I need to do it by chunks. First I tried vertically:</p>
  
  <pre><code>%%timeit
  for k in xrange(100) :
      x[ :, k ] = nr.random( 10000 )
  
  1 loops, best of 3: 255 ms per loop
  </code></pre>
  
  <p>Then I tried horizontally:</p>
  
  <pre><code>%%timeit
  for k in xrange(0, 10000, 100) :
      x[ k:k+100, : ] = nr.random( ( 100, 100 ) )
  
  100 loops, best of 3: 22.4 ms per loop
  </code></pre>
  
  <p>Why is the horizontal one 10 times faster? Also, is there a simpler way to do that?</p>