home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 403378297

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
403378297 MDU6SXNzdWU0MDMzNzgyOTc= 2714 Extra dimension on first argument passed into apply_ufunc 1796208 open 0     13 2019-01-26T00:04:47Z 2022-05-06T03:03:00Z   NONE      

Here's my code:

```python import numpy as np import xarray as xr

da = xr.DataArray(np.random.rand(1000, 100)) da = da.rename({'dim_0': 'rows_a'}) db = xr.DataArray(np.random.rand(1000, 100)) db = db.rename({'dim_0': 'rows_b'})

def print_shape(a): print(a.shape) return np.zeros(shape=(a.shape[0]))

def print_two_shapes(a, b): print(a.shape) print(b.shape) return np.zeros(shape=(a.shape[0], b.shape[0])) ```

If I print_shape and print_shapes with apply_ufunc I am surprised by the results:

```python xr.apply_ufunc( print_shape, da, input_core_dims=[['dim_1']] )

(1000, 100) <xarray.DataArray (rows_a: 1000)> array([0., 0., 0., ..., 0., 0., 0.]) Coordinates: * rows_a (rows_a) int64 0 1 2 3 4 5 6 7 ... 992 993 994 995 996 997 998 999 ```

vs

```python xr.apply_ufunc( print_two_shapes, da, db, input_core_dims=[['dim_1'], ['dim_1']] )

(1000, 1, 100) (1000, 100)

<xarray.DataArray (rows_a: 1000, rows_b: 1000)> array([[0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]]) Coordinates: * rows_a (rows_a) int64 0 1 2 3 4 5 6 7 ... 992 993 994 995 996 997 998 999 * rows_b (rows_b) int64 0 1 2 3 4 5 6 7 ... 992 993 994 995 996 997 998 999 ```

My array da has changed shape from (1000, 100) to (1000, 1, 100) when a second argument was added to my call to apply_ufunc.

Maybe this is documented, but I missed it. If it is documented I'd be glad to be pointed to it and I'll see if I can come up with a suggestion of how to highlight this better in the documentation as it really threw me.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2714/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 13 rows from issue in issue_comments
Powered by Datasette · Queries took 1.122ms · About: xarray-datasette