From: Daehyok S. <sd...@em...> - 2000-11-29 21:28:05
|
Comparing the performance, resize() seems to be more effient than ones(). Daehyok Shin ----- Original Message ----- From: "Chris Barker" <cb...@jp...> Cc: <num...@li...> 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. > cb...@jp... --- --- --- > http://www.jps.net/cbarker -----@@ -----@@ -----@@ > ------@@@ ------@@@ ------@@@ > Water Resources Engineering ------ @ ------ @ ------ @ > Coastal and Fluvial Hydrodynamics ------- --------- -------- > ------------------------------------------------------------------------ > ------------------------------------------------------------------------ > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > http://lists.sourceforge.net/mailman/listinfo/numpy-discussion > |