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/2805#issuecomment-1255029201,https://api.github.com/repos/pydata/xarray/issues/2805,1255029201,IC_kwDOAMm_X85KzjnR,32069530,2022-09-22T13:30:26Z,2022-09-22T16:12:47Z,NONE,"Hello guys,
While waiting for a integrated solution. Here is a function that should do the job in a safe way. It returns an iterator
````
def xndindex(ds, dims=None):
if dims is None:
dims = ds.dims
elif type(dims) is str:
dims=[dims]
else:
pass
for d in dims:
if d not in ds.dims:
raise ValueError(""Invalid dimension '{}'. Available dimensions {}"".format(d, ds.dims))
iter_dict = {k:v for k,v in ds.sizes.items() if k in dims}
for d,k in zip(repeat(tuple(iter_dict.keys())),zip(np.ndindex(tuple(iter_dict.values())))):
yield {k:l for k,l in zip(d,k[0])}
````
Example of use
````
a = xr.DataArray(np.random.rand(4,3), dims=['x','y'], coords={'x':np.arange(4), 'y':np.arange(3)})
for i in xndindex(a):
print(a[i])
````
","{""total_count"": 2, ""+1"": 2, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,419543087
https://github.com/pydata/xarray/issues/2805#issuecomment-1239645797,https://api.github.com/repos/pydata/xarray/issues/2805,1239645797,IC_kwDOAMm_X85J435l,32069530,2022-09-07T16:53:34Z,2022-09-07T17:00:44Z,NONE,"Hi guys,
For now, when I want to iterate over all my dataset I use the simple (but dangerous I believe) workaround:
````
for i in np.ndindex(ds.shape):
res = ds[{d:j for d,j in zip(ds.dims,i)}]
````
but, I am not sure that ndindex will iterate in the good order relatively to the ds.dims return.
Is there any news on this topic ?
Many thanks !","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,419543087