[NumPy-Tickets] [NumPy] #2238: Speed up array(list)

NumPy Trac numpy-tickets@scipy....
Wed Oct 31 07:25:47 CDT 2012


#2238: Speed up array(list)
-------------------------+--------------------------------------------------
 Reporter:  sbyrnes321   |       Owner:  somebody   
     Type:  enhancement  |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  numpy.core   |     Version:  1.6.2      
 Keywords:               |  
-------------------------+--------------------------------------------------
 http://stackoverflow.com/questions/13131220/building-a-small-numpy-array-
 from-individual-values-fast-and-readable-method

 As discussed here, array() is extremely slow at making an array from a
 python list or list-of-lists, based on comparison with other methods. For
 example, fromiter([1,2,3,4],dtype=float) runs five times faster than
 array([1,2,3,4],dtype=float). Likewise,
 fromiter([1,2,3,4],dtype=float).reshape((2,2)) is five times faster than
 array([[1,2],[3,4]]).

 I admit that a well-structured numpy program should be minimizing the
 number of times that new arrays are created from lists. Yet if there is a
 way to speed it up - and there does seem to be a lot of room for
 improvement - it seems well worth doing. It is not a rare operation!

 One idea might be an optional "dimensions" parameter in array, that would
 remove some overhead of inferring the number of rows, columns, etc. in the
 input. (Analogous to "count" in fromiter().) The array creation would
 throw an error if it is discovered that the "dimensions" input does not
 match the data. (I don't know how much that would help -- I haven't
 examined the internals -- it's just an idea.)

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/2238>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list