home / github

Menu
  • GraphQL API
  • Search all tables

issue_comments

Table actions
  • GraphQL API for issue_comments

5 rows where issue = 594900245 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: reactions, created_at (date), updated_at (date)

user 2

  • zxdawn 3
  • dcherian 2

author_association 2

  • NONE 3
  • MEMBER 2

issue 1

  • Sum based on start_index and end_index array · 5 ✖
id html_url issue_url node_id user created_at updated_at ▲ author_association body reactions performed_via_github_app issue
610142267 https://github.com/pydata/xarray/issues/3941#issuecomment-610142267 https://api.github.com/repos/pydata/xarray/issues/3941 MDEyOklzc3VlQ29tbWVudDYxMDE0MjI2Nw== zxdawn 30388627 2020-04-07T02:45:26Z 2020-04-07T02:45:26Z NONE

@dcherian Sorry for the misunderstanding. I tried again for the 3d array, it works well ;) ``` import xarray as xr import numpy as np

x = 2 y = 4 z = 3 data = np.arange(xyz).reshape(z, x, y)

input array

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

start_index array

sindex = xr.DataArray(np.full_like(a[0, ...], 0), dims=['y', 'x'])

end_index array

eindex = xr.DataArray(np.full_like(a[0, ...], 1), dims=['y', 'x'])

zindex = a.z.copy(data=np.arange(a.sizes["z"]))

sub_z = (zindex >= sindex) & (zindex <= eindex) sum_a = a.where(sub_z).sum('z', keepdims=True)

print(a) print(sum_a) ```

``` <xarray.DataArray (z: 3, y: 2, x: 4)> array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7]],

   [[ 8,  9, 10, 11],
    [12, 13, 14, 15]],

   [[16, 17, 18, 19],
    [20, 21, 22, 23]]])

Dimensions without coordinates: z, y, x

<xarray.DataArray (z: 1, y: 2, x: 4)> array([[[ 8., 10., 12., 14.], [16., 18., 20., 22.]]]) Dimensions without coordinates: z, y, x ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Sum based on start_index and end_index array 594900245
609882875 https://github.com/pydata/xarray/issues/3941#issuecomment-609882875 https://api.github.com/repos/pydata/xarray/issues/3941 MDEyOklzc3VlQ29tbWVudDYwOTg4Mjg3NQ== dcherian 2448579 2020-04-06T15:59:37Z 2020-04-06T15:59:37Z MEMBER

why not?

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Sum based on start_index and end_index array 594900245
609850841 https://github.com/pydata/xarray/issues/3941#issuecomment-609850841 https://api.github.com/repos/pydata/xarray/issues/3941 MDEyOklzc3VlQ29tbWVudDYwOTg1MDg0MQ== zxdawn 30388627 2020-04-06T15:04:23Z 2020-04-06T15:04:23Z NONE

@dcherian Excellent solution!

If we upgrade this to 3d array and sum by z axis, it seems that method isn't suitable:

``` import xarray as xr import numpy as np

x = 2 y = 2 z = 3 data = np.arange(xyz).reshape(z, y, x)

input array

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

start_index array

sindex = xr.DataArray(np.full_like(a[0, ...], 0), dims=['y', 'x'])

end_index array

eindex = xr.DataArray(np.full_like(a[0, ...], 1), dims=['y', 'x']) ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Sum based on start_index and end_index array 594900245
609827384 https://github.com/pydata/xarray/issues/3941#issuecomment-609827384 https://api.github.com/repos/pydata/xarray/issues/3941 MDEyOklzc3VlQ29tbWVudDYwOTgyNzM4NA== dcherian 2448579 2020-04-06T14:24:53Z 2020-04-06T14:24:53Z MEMBER

where is usually the solution for this kind of problem. I added the keepdims to keep the y dimension after the sum.

python yindex = a.y.copy(data=np.arange(a.sizes["y"])) # generate DataArray of indexes a.where((yindex >= sindex) & (yindex <= eindex)).sum("y", keepdims=True)

Please close if this answers your question.

{
    "total_count": 4,
    "+1": 4,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Sum based on start_index and end_index array 594900245
609728948 https://github.com/pydata/xarray/issues/3941#issuecomment-609728948 https://api.github.com/repos/pydata/xarray/issues/3941 MDEyOklzc3VlQ29tbWVudDYwOTcyODk0OA== zxdawn 30388627 2020-04-06T11:09:10Z 2020-04-06T11:09:10Z NONE

Solution (Boolean)

```

stack indexes

index_list = np.column_stack((sindex, eindex))

all false array

boolean_array = np.zeros(a.shape, dtype=bool)

iterate and assign true

for row in range(len(index_list)): boolean_array[row, np.arange(index_list[row][0], index_list[row][1]+1)] = True

sum_a = a.where(boolean_array).sum(dim='y') ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  Sum based on start_index and end_index array 594900245

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issue_comments] (
   [html_url] TEXT,
   [issue_url] TEXT,
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [created_at] TEXT,
   [updated_at] TEXT,
   [author_association] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [issue] INTEGER REFERENCES [issues]([id])
);
CREATE INDEX [idx_issue_comments_issue]
    ON [issue_comments] ([issue]);
CREATE INDEX [idx_issue_comments_user]
    ON [issue_comments] ([user]);
Powered by Datasette · Queries took 12.886ms · About: xarray-datasette