[Numpy-discussion] Turn numpy.ones_like into a ufunc

Marten van Kerkwijk m.h.vankerkwijk at gmail.com
Sat May 19 21:12:49 EDT 2018


Just for completeness: this is *not* an issue for ndarray subclasses,
but only for people attempting to write duck arrays.  One might want
to start by mimicking `empty_like` - not too different from
`np.positive(a, where=False)`. Will note that that is 50 times slower
for small arrays since it actually does the copying - it just doesn't
store the results. It is comparable in time to np.zeros_like and
np.ones_like, suggesting
that a ufunc implementation is not necessarily a bad thing.

As I noted above, the main problem I see is that the ufunc mechanism
doesn't easily work with strings and voids/structured dtypes.

-- Marten


More information about the NumPy-Discussion mailing list