home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 595900209

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
595900209 MDU6SXNzdWU1OTU5MDAyMDk= 3949 Index 3D array with index of last axis stored in 2D array 30388627 closed 0     2 2020-04-07T14:13:39Z 2020-04-07T14:30:12Z 2020-04-07T14:30:12Z NONE      

This is copied from a question on stackoverflow.

I have a ndarray of shape(z,y,x) containing values. I am trying to index this array with another ndarray of shape(y,x) that contains the z-index of the value I am interested in. How do I have to index val_arr with z_indices to get the values at the desired z-axis position?

MCVE Code Sample

```python import numpy as np val_arr = np.arange(27).reshape(3, 3, 3)

z_indices = np.array([[1, 0, 2], [0, 0, 1], [2, 0, 1]])

index_array = z_indices.choose(val_arr) print(index_array) ```

xarray version

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

val_arr = xr.DataArray(np.arange(27).reshape(3, 3, 3), dims=['z', 'y', 'x'])

z_indices = xr.DataArray(np.array([[1, 0, 2], [0, 0, 1], [2, 0, 1]]), dims=['y', 'x'])

index_array = np.choose(z_indices, val_arr) print(index_array) ```

Expected Output

<xarray.DataArray (y: 3, x: 3)> array([[ 9, 1, 20], [ 3, 4, 14], [24, 7, 17]]) Dimensions without coordinates: y, x

Problem Description

Is this feature of choose supported in xarray?

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3949/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

  • 0 rows from issues_id in issues_labels
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 0.521ms · About: xarray-datasette