[Numpy-discussion] New numpy functions: filled, filled_like

eat e.antero.tammi at gmail.com
Sun Jan 13 13:27:42 EST 2013


Hi,

On Sun, Jan 13, 2013 at 7:27 PM, Nathaniel Smith <njs at pobox.com> wrote:

> Hi all,
>
> PR 2875 adds two new functions, that generalize zeros(), ones(),
> zeros_like(), ones_like(), by simply taking an arbitrary fill value:
>   https://github.com/numpy/numpy/pull/2875
> So
>   np.ones((10, 10))
> is the same as
>   np.filled((10, 10), 1)
>
> The implementations are trivial, but the API seems useful because it
> provides an idiomatic way of efficiently creating an array full of
> inf, or nan, or None, whatever funny value you need. All the
> alternatives are either inefficient (np.ones(...) * np.inf) or
> cumbersome (a = np.empty(...); a.fill(...)). Or so it seems to me. But
> there's a question of taste here; one could argue instead that these
> just add more clutter to the numpy namespace. So, before we merge,
> anyone want to chime in?
>
> (Bonus, extra bike-sheddy survey: do people prefer
>   np.filled((10, 10), np.nan)
>   np.filled_like(my_arr, np.nan)
>
+0
OTOH, it might also be handy to let val to be an array as well, which is
then repeated to fill the array.

My 2 cents.
-eat

> or
>   np.filled(np.nan, (10, 10))
>   np.filled_like(np.nan, my_arr)
> ?)
>
> -n
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130113/067aa0f9/attachment.html>


More information about the NumPy-Discussion mailing list