[Numpy-discussion] Initialization of array?
sdhyok at email.unc.edu
Wed Nov 29 18:37:54 CST 2000
Initialization on huge arrays is frequent operations in scientific
It must be efficient as much as possible.
So, I was surprisized to see the inner codes of ones() in Numpy.
It maybe use calloc() rather than malloc() in C level,
then for(..) for addition.
Why not use malloc() and for(...) simultaneously in C level
with a command such as:
a = arrray(1,shape=(10000,10000))
----- Original Message -----
From: "Rob W. W. Hooft" <rob at hooft.net>
To: "Daehyok Shin" <sdhyok at email.unc.edu>
Cc: <numpy-discussion at lists.sourceforge.net>
Sent: Wednesday, November 29, 2000 1:00 PM
Subject: Re: [Numpy-discussion] Initialization of array?
> >>>>> "DS" == Daehyok Shin <sdhyok at email.unc.edu> writes:
> DS> When I initialize an array, I use a = ones(shape)*initial_val
> DS> But, I am wondering if Numpy has more efficient way. For example,
> DS> a = array(initial_value, shape)
> Looking at the definition of "ones":
> def ones(shape, typecode='l', savespace=0):
> """ones(shape, typecode=Int, savespace=0) returns an array of the
> dimensions which is initialized to all ones.
> return zeros(shape, typecode, savespace)+array(1, typecode)
> It looks like you could try a=zeros(shape)+initial_val instead.
> Hm.. I might do some experimenting.
> ===== rob at hooft.net http://www.hooft.net/people/rob/ =====
> ===== R&D, Nonius BV, Delft http://www.nonius.nl/ =====
> ===== PGPid 0xFA19277D ========================== Use Linux! =========
More information about the Numpy-discussion