[Numpy-discussion] {zeros, empty, ...}_like functions behavior with subclasses

Bruce Southey bsouthey@gmail....
Mon Feb 28 18:05:06 CST 2011


On Mon, Feb 28, 2011 at 4:52 PM, Wes McKinney <wesmckinn@gmail.com> wrote:
> 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
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

I guess this is ticket 929.
http://projects.scipy.org/numpy/ticket/929

I was looking at it today but was not sure what is really desired
here. I considered that this just meant shape and dtype but not sure
about masked or record arrays behavior. So:
What is the value of having the metadata?
What is the meaning of 'like' here?

Bruce


More information about the NumPy-Discussion mailing list