I had another look at the definition of "ones" and of
another routine
> I frequently use: arange. It appears that even
without rewriting them
> in C, some speedup can be achieved: > > - in ones(), the + 1 should be done \"in
place", saving about 15%, more
> if you run out of processor cache: I\'d also try assignment in place: def ones(shape, typecode=\'l\', savespace=0): a = zeros(shape, typecode, savespace) a[len(shape)*[slice(0, None)]] = 1 return a Konrad.
Is the following definition faster or not?
def ones(shape, typecode='l', savespace=0): a = zeros( (product(shape),), typecode, savespace) a[:] = 1 a.shape = shape return a
Zaur
"s" == szport szport@runet.com writes:
s> Is the following definition faster or not?
s> def ones(shape, typecode='l', savespace=0): s> a = zeros( (product(shape),), typecode, savespace) s> a[:] = 1 s> a.shape = shape s> return a
This is yet another way to write a[...]=1 manually via a small detour. For small arrays (size 10...1000) it is about twice slower than writing [...] (0.1ms slower per call on my workstation).
Rob