[Numpy-discussion] New numpy functions: filled, filled_like
Mon Jan 14 09:12:47 CST 2013
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;
On Mon, Jan 14, 2013 at 9:57 AM, Benjamin Root <firstname.lastname@example.org> wrote:
> On Mon, Jan 14, 2013 at 7:38 AM, Pierre Haessig <email@example.com>
>> 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.
> 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
More information about the NumPy-Discussion