list to array is slow
Hi, any idea why the simple code below is so slow ? import numpy as n from time import time as t dims = (640,480) m = n.random.random( dims ) l=[] for i in range(200): l.append(m) t0=t() b=n.array(l) print t()-t0 To convert the list into an array takes about 5 sec ... Thanks, marco
On Thu, Jul 22, 2010 at 2:09 PM, marco cammarata
To convert the list into an array takes about 5 sec ...
Not too familiar with typical speeds, but at a guess, perhaps because it must convert 61.4 million (640*480*200) values? Just to *count* that high with xrange takes 1.6 seconds for my computer. I imagine doing further operations (like converting into a numpy array) on other Python objects (like lists) might be similarly slow. Ian
On Thu, Jul 22, 2010 at 5:09 PM, marco cammarata
Hi,
any idea why the simple code below is so slow ?
import numpy as n from time import time as t
dims = (640,480) m = n.random.random( dims )
l=[]
for i in range(200): l.append(m)
t0=t() b=n.array(l) print t()-t0
To convert the list into an array takes about 5 sec ...
There was a recent thread that covers similar ground. "Stacking arrays along new dimension in front" http://www.mail-archive.com/numpy-discussion@scipy.org/msg26772.html I think the fastest way was to do b = n.concatenate(a_[None] for a_ in l) but I could be mistaken, and there should probably be a more general solution to this problem. Skipper
participants (3)
-
Ian Mallett
-
marco cammarata
-
Skipper Seabold