
Initialization on huge arrays is frequent operations in scientific programming. 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)) Daehyok Shin ----- Original Message ----- From: "Rob W. W. Hooft" <rob@hooft.net> To: "Daehyok Shin" <sdhyok@email.unc.edu> Cc: <numpy-discussion@lists.sourceforge.net> Sent: Wednesday, November 29, 2000 1:00 PM Subject: Re: [Numpy-discussion] Initialization of array?
"DS" == Daehyok Shin <sdhyok@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 given 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
-- ===== rob@hooft.net http://www.hooft.net/people/rob/ ===== ===== R&D, Nonius BV, Delft http://www.nonius.nl/ ===== ===== PGPid 0xFA19277D ========================== Use Linux! =========