home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 594900245

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
594900245 MDU6SXNzdWU1OTQ5MDAyNDU= 3941 Sum based on start_index and end_index array 30388627 closed 0     5 2020-04-06T08:15:57Z 2020-04-07T02:45:26Z 2020-04-07T02:45:26Z NONE      

I have three arrays: 1. a: input array 2. sindex: the array containing the start index for summation 3. eindex: the array containing the end index for summation

MCVE Code Sample

```python import xarray as xr data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])

input array

a = xr.DataArray(data, dims=['x', 'y'])

start_index array

sindex = xr.DataArray(np.array([0, 0, 1, 1]), dims=['x'])

end_index array

eindex = xr.DataArray(np.array([0, 1, 2, 2]), dims=['x'])

empty array for saving summation

sum_a = xr.DataArray(np.empty((a.shape[0], 1)), dims=['x', 'y'])

for x in a.x: # sum values from sindex to eindex at row x sum_a[x] = a[x, sindex[x].values:eindex[x].values+1].sum()

print(sum_a) ```

Expected Output

<xarray.DataArray (x: 4, y: 1)> array([[ 1.], [ 9.], [17.], [23.]]) Dimensions without coordinates: x, y

Problem Description

Is it necessary to use xr.apply_ufunc? or any other good method?

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

Links from other tables

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