[Numpy-discussion] Initialization of array?
Rob W. W. Hooft
rob at hooft.net
Wed Nov 29 15:00:58 CST 2000
>>>>> "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 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 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
mailing list