
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 -- ===== rob@hooft.net http://www.hooft.net/people/rob/ ===== ===== R&D, Nonius BV, Delft http://www.nonius.nl/ ===== ===== PGPid 0xFA19277D ========================== Use Linux! =========

"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 -- ===== rob@hooft.net http://www.hooft.net/people/rob/ ===== ===== R&D, Nonius BV, Delft http://www.nonius.nl/ ===== ===== PGPid 0xFA19277D ========================== Use Linux! =========
participants (2)
-
rob@hooft.net
-
szport@runet.com