id,node_id,number,title,user,state,locked,assignee,milestone,comments,created_at,updated_at,closed_at,author_association,active_lock_reason,draft,pull_request,body,reactions,performed_via_github_app,state_reason,repo,type
1298145215,I_kwDOAMm_X85NYB-_,6763,Map_blocks should raise nice error if provided template has no dask arrays,2448579,closed,0,,,3,2022-07-07T21:58:06Z,2022-07-14T17:42:26Z,2022-07-14T17:42:26Z,MEMBER,,,,"### Discussed in https://github.com/pydata/xarray/discussions/6762
Originally posted by **tlsw231** July 7, 2022
I am trying to use `map_blocks` to: ingest a multi-dimensional array as input, reduce along one dimension and add extra dimensions to the output. Is this possible? I am attaching a simple MRE below that gives me an `zip argument #2 must support iteration` error. Any pointers on what I might be doing wrong?
[My real example is a 3d-dataset with `(time,lat,lon)` dimensions and I am trying to reduce along `time` while adding two new dimensions to the output. I tried so many things and got so many errors, including the one in the title, that I thought it is better to first understand how `map_blocks` works!]
```
# The goal is to feed in a 2d array, reduce along one dimension and add two new dimensions to the output.
chunks={}
dummy = xr.DataArray(data=np.random.random([8,100]),dims=['dim1','dim2']).chunk(chunks)
def some_func(func):
dims=func.dims
n1 = len(func[func.dims[1]]) # This is 'dim2', we will average along 'dim1' below in the for loop
newdim1 = 2; newdim2 = 5;
output = xr.DataArray(np.nan*np.ones([n1,newdim1,newdim2]),dims=[dims[1],'new1','new2'])
for n in range(n1):
fmean = func.isel(dim2=n).mean(dims[0]).compute()
for i in range(newdim1):
for j in range(newdim2):
output[n,i,j] = fmean
return output
#out = some_func(dummy) # This works
template=xr.DataArray(np.nan*np.ones([len(dummy.dim2),2,5]),
dims=['dim2','new1','new2'])
out = xr.map_blocks(some_func,dummy,template=template).compute() # gives me the error message in the title
```
[Edit: Fixed a typo in the `n1 = len(func[func.dims[1]])` line, of course getting the same error.]
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6763/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue