home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 310670696

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
310670696 MDU6SXNzdWUzMTA2NzA2OTY= 2035 Manually subtracting two slices of DataArary always produces zero output 13205162 closed 0     5 2018-04-03T02:22:00Z 2019-01-22T22:44:43Z 2019-01-22T22:44:43Z CONTRIBUTOR      

I have witnessing a weird behavior with xarray. Here's a MWE

python import xarray as xr da=xr.DataArray(np.random.rand(5,5,5), dims=['x', 'y', 'z'], coords=dict(x=range(5), y=range(5), z=range(5))) da[...,1:]-da[...,:-1] I expected this work just as da.diff(dim='z'), but it always returns a zero-values DataArray.

Expected Output

``` <xarray.DataArray (x: 5, y: 5, z: 4)> array([[[-0.22148 , 0.246586, 0.043931, -0.37468 ], [-0.522721, -0.016258, -0.386125, 0.932965], [-0.227799, -0.140233, 0.400886, -0.130469], [-0.04763 , 0.656787, -0.597745, 0.212088], [ 0.089159, 0.376483, -0.712572, 0.397021]],

   [[ 0.161166, -0.387264,  0.052542,  0.477284],
    [ 0.30892 ,  0.426818, -0.370983,  0.059737],
    [ 0.429502, -0.395471,  0.238937,  0.360634],
    [ 0.702574, -0.150469,  0.300272, -0.483837],
    [ 0.419341,  0.317944, -0.089965, -0.102932]],

   [[ 0.371919, -0.140948,  0.583743, -0.827194],
    [-0.037487, -0.345201, -0.457696,  0.281395],
    [ 0.43892 ,  0.156371, -0.351781, -0.016645],
    [-0.542661,  0.51394 , -0.615431, -0.039449],
    [-0.439784, -0.153804,  0.314933, -0.539498]],

   [[-0.398652,  0.830793, -0.408786, -0.355191],
    [-0.757028, -0.017731,  0.086872, -0.182064],
    [ 0.174183, -0.075571,  0.604353, -0.347382],
    [-0.388407,  0.342358,  0.059482,  0.347141],
    [ 0.759616, -0.446468, -0.060504, -0.217946]],

   [[-0.283018, -0.078172,  0.276102, -0.236144],
    [-0.427625, -0.044339,  0.484844, -0.06352 ],
    [-0.073386,  0.336733,  0.429961, -0.839064],
    [ 0.256269, -0.586563, -0.076288, -0.220549],
    [ 0.320014, -0.633854, -0.026103,  0.333301]]])

Coordinates: * z (z) int64 1 2 3 4 * y (y) int64 0 1 2 3 4 * x (x) int64 0 1 2 3 4 ```

The output I'm getting is:

``` <xarray.DataArray (x: 5, y: 5, z: 3)>
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.],                                                                                                                                                        
    [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.],                                                                                                                                                        
    [0., 0., 0.]]])

Coordinates:
* z (z) int64 1 2 3
* y (y) int64 0 1 2 3 4 * x (x) int64 0 1 2 3 4

```

Is there something I'm missing here or is this really the expected behavior?

Output of xr.show_versions()

xarray: 0.10.2 pandas: 0.22.0 numpy: 1.14.2 scipy: 1.0.0 netCDF4: 1.2.6 h5netcdf: 0.3.1 h5py: 2.6.0 Nio: None zarr: None bottleneck: None cyordereddict: None dask: 0.17.2 distributed: None matplotlib: 2.1.0 cartopy: None seaborn: None setuptools: 38.2.4 pip: 9.0.3 conda: None pytest: None IPython: 6.2.1 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2035/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

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