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 https://github.com/pydata/xarray/issues/2805#issuecomment-471978276,https://api.github.com/repos/pydata/xarray/issues/2805,471978276,MDEyOklzc3VlQ29tbWVudDQ3MTk3ODI3Ng==,23265127,2019-03-12T12:23:23Z,2019-03-12T12:23:23Z,NONE,"Hi shoyer, many thanks for your quick reply. Converting the xarray to a DataFrame indeed does the job and I will use this solution for the time being. Nevertheless, to me the approach seems rather like an ad-hoc solution since it requires a series of conversions / function calls and I feel like there should be some built-in solution from xarray. In particular, in the above solution, you lose track of what are the coordinates and what is the actual data (all is stored in a single NamedTuple), which requires an additional step to separate the two data structures. Anyway, thanks for your help! If you find another solution, please let me know!","{""total_count"": 3, ""+1"": 3, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,419543087 https://github.com/pydata/xarray/issues/2805#issuecomment-471768511,https://api.github.com/repos/pydata/xarray/issues/2805,471768511,MDEyOklzc3VlQ29tbWVudDQ3MTc2ODUxMQ==,1217238,2019-03-11T22:40:28Z,2019-03-11T22:40:28Z,MEMBER,"You could convert your data into pandas and use `.itertuples()`, e.g., ```python import xarray import itertools ds = xarray.tutorial.open_dataset('air_temperature') records = ds.to_dataframe().reset_index().itertuples(index=False, name='Record') print(list(itertools.islice(records, 5))) ``` Outputs: ``` [Record(lat=75.0, lon=200.0, time=Timestamp('2013-01-01 00:00:00'), air=241.1999969482422), Record(lat=75.0, lon=200.0, time=Timestamp('2013-01-01 06:00:00'), air=242.09999084472656), Record(lat=75.0, lon=200.0, time=Timestamp('2013-01-01 12:00:00'), air=242.29998779296875), Record(lat=75.0, lon=200.0, time=Timestamp('2013-01-01 18:00:00'), air=241.88999938964844), Record(lat=75.0, lon=200.0, time=Timestamp('2013-01-02 00:00:00'), air=243.1999969482422)] ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,419543087