8000 numpy sum returns unrecognized objects unchanged · Issue #8927 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
numpy sum returns unrecognized objects unchanged #8927
Open
@KesterTong

Description

@KesterTong

When passed an object that isn't array-like, numpy.sum returns that object. This is surprising behavior. Maybe it is consistent with interpreting the input as a scalar, but it is surprising when the input is iterable. E.g.

class A(object):
  pass

a = A()
np.sum(a)  # returns `a`

Note that this occurs even for iterables, e.g.

class A(object):
  def __getitem__(self, index):
    if index > 3:
        raise IndexError("that's enough!")

    return index

a = A()
np.sum(a)  # returns `a`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0