[Numpy-discussion] New numpy functions: filled, filled_like
Pierre Haessig
pierre.haessig@crans....
Thu Jan 17 08:02:51 CST 2013
Hi,
Le 14/01/2013 20:17, Alan G Isaac a écrit :
> >>> a = np.tile(5,(1,2,3))
> >>> a
> array([[[5, 5, 5],
> [5, 5, 5]]])
> >>> np.tile(1,a.shape)
> array([[[1, 1, 1],
> [1, 1, 1]]])
>
> I had not realized a scalar first argument was possible.
I didn't know either ! I discovered this use in the thread of this
discussion. Just like Ben, I've almost never used "np.tile" neither its
cousin "np.repeat"...
Now, in the process of rediscovering those two functions, I was just
wondering whether it would make sense to repackage them in order to
allow the simple functionality of initializing a non-empty array.
In term of choosing the name (or actually the verb), I prefer "repeat"
because it's a more familiar concept than "tile". However, repeat may
need more changes to make it work than tile. Indeed we currently have :
>>> tile(nan, (3,3)) # works fine, but is pretty slow for that purpose,
And doesn't accept a dtype arg
array([[ nan, nan, nan],
[ nan, nan, nan],
[ nan, nan, nan]])
Doesn't work for that purpose:
>>>repeat(nan, (3,3))
[...]
ValueError: a.shape[axis] != len(repeats)
So what people think of this "green" approach of recycling existing API
into a slightly different function (without breaking current behavior of
course)
Best,
Pierre
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130117/ead70f5d/attachment.bin
More information about the NumPy-Discussion
mailing list