home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 410488222

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/2340#issuecomment-410488222 https://api.github.com/repos/pydata/xarray/issues/2340 410488222 MDEyOklzc3VlQ29tbWVudDQxMDQ4ODIyMg== 90008 2018-08-05T01:15:39Z 2018-08-05T01:15:49Z CONTRIBUTOR

Finishing up this line of though: without the assumption that the relative order of dimensions is maintained across arrays in a set, this feature is impossible to implement as a neat function call. You would have to specify exactly how to expand each of the coordinates which can get pretty long.

I wrote some code, that I think should have worked if relative ordering was a valid assumption: Here it is for reference https://github.com/hmaarrfk/xarray/pull/1

To obtain the desired effect, you have to expand the dimensions of the coordinates individually: ```python import xarray as xr import numpy as np

Setup an array with coordinates

n = np.arange(1, 13).reshape(3, 2, 2) coords={'y': np.arange(1, 4), 'x': np.arange(1, 3), 'xi': np.arange(2)}

%%

z = xr.DataArray(n[..., 0]2, dims=['y', 'x']) a = xr.DataArray(n, dims=['y', 'x', 'xi'], coords={*coords, 'z': z})

sliced = a[0] print("The original xarray") print(a.z) print("The sliced xarray") print(sliced.z)

%%

expanded = sliced.expand_dims('y', 0) expanded['z'] = expanded.z.expand_dims('y', 0) print(expanded) ```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  347558405
Powered by Datasette · Queries took 0.608ms · About: xarray-datasette