[Numpy-discussion] {zeros, empty, ...}_like functions behavior with subclasses
Wes McKinney
wesmckinn at gmail.com
Mon Feb 28 17:52:14 EST 2011
I'm having some trouble with the zeros_like function via np.fix:
def zeros_like(a):
if isinstance(a, ndarray):
res = ndarray.__new__(type(a), a.shape, a.dtype, order=a.flags.fnc)
res.fill(0)
return res
try:
wrap = a.__array_wrap__
except AttributeError:
wrap = None
a = asarray(a)
res = zeros(a.shape, a.dtype)
if wrap:
res = wrap(res)
return res
As you can see this is going to discard any metadata stored in a
subtype. I'm not sure whether this is a bug or a feature but wanted to
bring it up.
Thanks,
Wes
More information about the NumPy-Discussion
mailing list