[Numpy-discussion] (no subject)

szport at runet.com szport at runet.com
Thu Nov 30 21:05:42 CST 2000


> 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





More information about the Numpy-discussion mailing list