On Fri, Feb 5, 2010 at 12:26, Keith Goodman <[email protected]> wrote: > Why is the second method of converting a list of tuples to an array so > much faster? > >>> x = range(500) >>> x = [(z,) for z in x] # <-- e.g. output of a sql database >>> x[:5] > [(0,), (1,), (2,), (3,), (4,)] >>> >>> timeit np.array(x).reshape(-1) # <-- slow > 1000 loops, best of 3: 832 us per loop >>> timeit np.array([z[0] for z in x]) > 10000 loops, best of 3: 106 us per loop # <-- fast
When array() gets a sequence of sequences, it has to do more work to figure out the appropriate shape. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
