issue_comments: 410420312
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-410420312 | https://api.github.com/repos/pydata/xarray/issues/2340 | 410420312 | MDEyOklzc3VlQ29tbWVudDQxMDQyMDMxMg== | 90008 | 2018-08-04T03:39:49Z | 2018-08-04T03:39:49Z | CONTRIBUTOR | @shoyer Thank you for your first detailed response. It definitely took me a while to understand all the intricacies of your words. In fact, if you do use a Dataset, as opposed to a DataArray, you are able to expand dims for multiple simultaneous arrays together. For my particular case, a Dataset is probably more appropriate, but I liked the fact that the DataArray had one of the Here is an example showing how if you use a Dataset, the behaviour I expect is obtained: ```python %%import xarray as xa import numpy as np n = np.zeros((3, 2)) data = xa.DataArray(n, dims=['y', 'x'], coords={'y':range(3), 'x':range(2)}) z=xa.DataArray(np.arange(6).reshape((3, 2)), dims=['y', 'x']) my_set = xa.Dataset({'mydata':data, 'z':z}) print('Original Data') print('=============') print(my_set) %%my_slice = my_set[{'x': 0, 'y':1}] print("Sliced data") print("===========") print("z coordinate remembers it's own x value") print(f'x = {my_slice.z.x}') %%expanded_slice = my_slice.expand_dims('x') print("expanded slice") print("==============") print("forgot that 'z' had 'x' coordinates") print("but remembered it had a 'y' coordinate") print(f"z = {expanded_slice.z}") print(expanded_slice.z.x) ``` Output:
|
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
347558405 |