home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 1074303184

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1074303184 I_kwDOAMm_X85ACJDQ 6053 A broadcasting sum for xarray.Dataset 4502 open 0     3 2021-12-08T11:24:21Z 2022-07-08T11:49:24Z   NONE      

I've found it useful to have a version of Dataset.sum which sums variables in a way that's consistent with what would happen if they were broadcast to the full Dataset dimensions.

The difference is in what it does with variables that don't contain some of the dimensions it's asked to sum over: standard sum just ignores the summation over these dimensions for these variables, whereas a broadcasting_sum will multiply the variable by the product of sizes the missing dimensions, like so:

python def broadcast_sum(dataset, dims): def broadcast_sum_var(var): present_sum_dims = [dim for dim in dims if dim in var.dims] non_present_sum_dims = [dim for dim in dims if dim not in var.dims] return var.sum(present_sum_dims) * np.prod([dataset.sizes[dim] for dim in non_present_sum_dims]) return dataset.map(broadcast_sum_var)

This is consistent with mathematical sum notation, where the sum doesn't become a no-op just because the summand doesn't reference the index being summed over. E.g.:

$\sum_{n=1}^N x = N x$

I've found it useful when you need to do some broadcasting operations across different variables after the sum, and you want the summation done in a way that's consistent with the broadcasting logic that will be applied later.

Would you be open to adding this, and if so any preference how? (A separate method, an option to .sum ?)

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/6053/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 3 rows from issue in issue_comments
Powered by Datasette · Queries took 0.676ms · About: xarray-datasette