issues: 860038564
This data as json
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
860038564 | MDU6SXNzdWU4NjAwMzg1NjQ= | 5173 | Clip broadcasts min or max array input | 5635139 | closed | 0 | 1 | 2021-04-16T17:41:27Z | 2021-04-21T19:06:48Z | 2021-04-21T19:06:48Z | MEMBER | Is your feature request related to a problem? Please describe.
Currently ```python In [11]: da = xr.DataArray(np.arange(24).reshape(2,4,3), dims=['a','b','c']) ...: da Out[11]: <xarray.DataArray (a: 2, b: 4, c: 3)> array([[[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]],
Dimensions without coordinates: a, b, c In [12]: da.clip(da.mean('a'))ValueError Traceback (most recent call last) <ipython-input-12-c8b9c6d0e0a1> in <module> ----> 1 da.clip(da.mean('a')) [...] ~/.asdf/installs/python/3.8.8/lib/python3.8/site-packages/xarray/core/computation.py in apply_variable_ufunc(func, signature, exclude_dims, dask, output_dtypes, vectorize, keep_attrs, dask_gufunc_kwargs, *args) 741 data = as_compatible_data(data) 742 if data.ndim != len(dims): --> 743 raise ValueError( 744 "applied function returned data with unexpected " 745 f"number of dimensions. Received {data.ndim} dimension(s) but " ValueError: applied function returned data with unexpected number of dimensions. Received 3 dimension(s) but expected 2 dimensions with names: ('b', 'c') ``` Adding in a ```python In [20]: da.clip(da.mean('a').broadcast_like(da)) Out[20]: <xarray.DataArray (a: 2, b: 4, c: 3)> array([[[ 6., 7., 8.], [ 9., 10., 11.], [12., 13., 14.], [15., 16., 17.]],
Dimensions without coordinates: a, b, c ``` Additional context Numpy broadcasts the argument: https://numpy.org/doc/stable/reference/generated/numpy.clip.html |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/5173/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |