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

Daniele Nicolodi daniele@grinta....
Fri Jan 18 10:57:36 CST 2013


On 18/01/2013 17:46, Benjamin Root wrote:
> 
> 
> On Fri, Jan 18, 2013 at 11:36 AM, Daniele Nicolodi <daniele@grinta.net
> <mailto:daniele@grinta.net>> wrote:
> 
>     On 18/01/2013 15:19, Benjamin Root wrote:
>     >
>     >
>     > On Fri, Jan 18, 2013 at 3:44 AM, Daniele Nicolodi
>     <daniele@grinta.net <mailto:daniele@grinta.net>
>     > <mailto:daniele@grinta.net <mailto:daniele@grinta.net>>> wrote:
>     >
>     >     On 17/01/2013 23:27, Mark Wiebe wrote:
>     >     > Would it be too weird or clumsy to extend the empty and
>     empty_like
>     >     > functions to do the filling?
>     >     >
>     >     > np.empty((10, 10), fill=np.nan)
>     >     > np.empty_like(my_arr, fill=np.nan)
>     >
>     >     Wouldn't it be more natural to extend the ndarray constructor?
>     >
>     >     np.ndarray((10, 10), fill=np.nan)
>     >
>     >     It looks more natural to me. In this way it is not possible to
>     have the
>     >     _like extension, but I don't see it as a major drawback.
>     >
>     >
>     >     Cheers,
>     >     Daniele
>     >
>     >
>     > This isn't a bad idea.  Although, I would wager that most people, like
>     > myself, use np.array() and np.array_like() instead of
>     np.ndarray().  We
>     > should also double-check and see how well that would fit in with the
>     > other contructors like masked arrays and matrix objects.
> 
>     Hello Ben,
> 
>     I don't really get what you mean with this. np.array() construct a numpy
>     array from an array-like object, np.ndarray() accepts a dimensions tuple
>     as first parameter, I don't see any np.array_like in the current numpy
>     release.
> 
>     Cheers,
>     Daniele
> 
> 
> My bad, I had a brain-fart and got mixed up.  I was thinking of
> np.empty().  In fact, I never use np.ndarray(), I use np.empty(). 
> Besides np.ndarray() being the actual constructor, what is the
> difference between them?

I was also wondering what's the difference between np.ndarray() and
np.empty(). I thought the second was a wrapper around the first, but it
looks like both of them are actually implemented in C...

Cheers,
Daniele



More information about the NumPy-Discussion mailing list