Why not optimize NumPy to detect a mul of an ndarray by a scalar to call fill? That way, "np.empty * 2" will be as fast as "x=np.empty; x.fill(2)"?
Fred On Mon, Jan 14, 2013 at 9:57 AM, Benjamin Root <ben.r...@ou.edu> wrote: > > > On Mon, Jan 14, 2013 at 7:38 AM, Pierre Haessig <pierre.haes...@crans.org> > wrote: >> >> Hi, >> >> Le 14/01/2013 00:39, Nathaniel Smith a écrit : >> > (The nice thing about np.filled() is that it makes np.zeros() and >> > np.ones() feel like clutter, rather than the reverse... not that I'm >> > suggesting ever getting rid of them, but it makes the API conceptually >> > feel smaller, not larger.) >> Coming from the Matlab syntax, I feel that np.zeros and np.ones are in >> numpy for Matlab (and maybe others ?) compatibilty and are useful for >> that. Now that I've been "enlightened" by Python, I think that those >> functions (especially np.ones) are indeed clutter. Therefore I favor the >> introduction of these two new functions. >> >> However, I think Eric's remark about masked array API compatibility is >> important. I don't know what other names are possible ? np.const ? >> >> Or maybe np.tile is also useful for that same purpose ? In that case >> adding a dtype argument to np.tile would be useful. >> >> best, >> Pierre >> > > I am also +1 on the idea of having a filled() and filled_like() function (I > learned a long time ago to just do a = np.empty() and a.fill() rather than > the multiplication trick I learned from Matlab). However, the collision > with the masked array API is a non-starter for me. np.const() and > np.const_like() probably make the most sense, but I would prefer a verb over > a noun. > > Ben Root > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion