Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datarray-specific fields should be present when returning scalars from reductions #21

Open
fperez opened this issue Jul 29, 2010 · 0 comments
Labels

Comments

@fperez
Copy link
Collaborator

fperez commented Jul 29, 2010

When an operation reduces the number of dimensions to zero, numpy returns a numpy scalar object:

In [33]: a = rand(10,10,10)

In [34]: a.sum()
Out[34]: 484.51400807908772

In [35]: _34.ndim
Out[35]: 0

In [36]: _34.shape
Out[36]: ()

For datarray, we can return scalars, but they will be plain numpy scalars, they won't have the extra datarray-specific fields (like labels, axes, ...). We can't add new fields to numpy scalars:

In [40]: _34.newfield=1
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'numpy.float64' object has no attribute 'newfield'

So this is not likely to change soon, but we want to record it here for later reference. If datarray is included in numpy, it may be easier to play with the scalar code to make datarray scalars have all the necessary fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant