code: def toarray(table, dtype=None, count=-1, sample=1000):
      
  
      import numpy as np
      it = iter(table)
      peek, it = iterpeek(it, sample)
      hdr = next(it)
      flds = list(map(str, hdr))
      dtype = construct_dtype(flds, peek, dtype)
  
      # numpy is fussy about having tuples, need to make sure
      it = (tuple(row) for row in it)
      sa = np.fromiter(it, dtype=dtype, count=count)
  
      return sa
docs: Load data from the given `table` into a
      `numpy <http://www.numpy.org/>`_ structured array. E.g.::
  
          >>> import petl as etl
          >>> table = [('foo', 'bar', 'baz'),
          ...          ('apples', 1, 2.5),
          ...          ('oranges', 3, 4.4),
          ...          ('pears', 7, .1)]
          >>> a = etl.toarray(table)
          >>> a
          array([('apples', 1, 2.5), ('oranges', 3, 4.4), ('pears', 7, 0.1)],
                dtype=(numpy.record, [('foo', '<U7'), ('bar', '<i8'), ('baz', '<f8')]))
          >>> # the dtype can be specified as a string
          ... a = etl.toarray(table, dtype='a4, i2, f4')
          >>> a
          array([(b'appl', 1, 2.5), (b'oran', 3, 4.4), (b'pear', 7, 0.1)],
                dtype=[('foo', 'S4'), ('bar', '<i2'), ('baz', '<f4')])
          >>> # the dtype can also be partially specified
          ... a = etl.toarray(table, dtype={'foo': 'a4'})
          >>> a
          array([(b'appl', 1, 2.5), (b'oran', 3, 4.4), (b'pear', 7, 0.1)],
                dtype=[('foo', 'S4'), ('bar', '<i8'), ('baz', '<f8')])
  
      If the dtype is not completely specified, `sample` rows will be
      examined to infer an appropriate dtype.