[Numpy-discussion] Initialization of array?
Daehyok Shin
sdhyok at email.unc.edu
Wed Nov 29 18:29:50 CST 2000
Comparing the performance,
resize() seems to be more effient than ones().
Daehyok Shin
----- Original Message -----
From: "Chris Barker" <cbarker at jps.net>
Cc: <numpy-discussion at lists.sourceforge.net>
Sent: Wednesday, November 29, 2000 11:13 AM
Subject: Re: [Numpy-discussion] Initialization of array?
> Daehyok Shin wrote:
> > When I initialize an array, I use
> > a = ones(shape)*initial_val
> >
> > But, I am wondering if Numpy has more efficient way.
> > For example,
> > a = array(initial_value, shape)
>
> I don't know if it's any more efficient (what you have is pretty fast
> already), but another option is to use resize:
>
> >>> shape = (3,4)
>
> >>> initial_val = 5.0
>
> >>> resize(initial_val,shape)
>
> array([[ 5., 5., 5., 5.],
> [ 5., 5., 5., 5.],
> [ 5., 5., 5., 5.]])
> >>>
>
> -Chris
>
>
> --
> Christopher Barker,
> Ph.D.
> cbarker at jps.net --- --- ---
> http://www.jps.net/cbarker -----@@ -----@@ -----@@
> ------@@@ ------@@@ ------@@@
> Water Resources Engineering ------ @ ------ @ ------ @
> Coastal and Fluvial Hydrodynamics ------- --------- --------
> ------------------------------------------------------------------------
> ------------------------------------------------------------------------
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> http://lists.sourceforge.net/mailman/listinfo/numpy-discussion
>
More information about the Numpy-discussion
mailing list