home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 419383633

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/2399#issuecomment-419383633 https://api.github.com/repos/pydata/xarray/issues/2399 419383633 MDEyOklzc3VlQ29tbWVudDQxOTM4MzYzMw== 514522 2018-09-07T09:39:01Z 2018-09-07T09:39:01Z CONTRIBUTOR

Now I see the problem. But I think it is solvable.

I will ignore the dimension names for now as I don't have much experience with xarray yet.

The code

python da_nonunique = xr.DataArray([0, 1], dims=['x'], coords={'x': ['a', 'a']} indexer = xr.DataArray([['a']], dims=['y', 'z'])

can be understood as defining two indexed arrays:

[a, a] and [[a]]. As we are allowing for non-unique indexing, I will denote unique array elements as [e_0, e_1] and [[r_0]] interchangeably.

Algorithm:

  1. Align. [[a], [a]] and [[a]].
  2. Ravel. [(a,a), (a,a)] and [(a,a)].
  3. Join. [(a,a), (a,a)]. I.e., [e_0, e_1].
  4. Unravel. [[e_0, e_1]]. Notice that [e_0, e_1] has been picked up by r_0.
  5. Reshape. [[e_0, e_1]] (solution).

Concretely, the solution is a bi-dimensional, 1x2 array:

| 0 1 |.

There is another relevant example. Let the code be

python da_nonunique = xr.DataArray([0, 1, 2], dims=['x'], coords={'x': ['a', 'a', 'b']} indexer = xr.DataArray([['a', 'b']], dims=['y', 'z'])

We have [a, a, b] and [[a, b]], also denoted as [e_0, e_1, e_2] and [[r_0, r_1]].

Algorithm:

  1. Align. [[a], [a], [b]] and [[a, b]].
  2. Ravel. [(a,a), (a,a), (b,b)] and [(a,a), (b,b)].
  3. Join. [(a,a), (a,a), (b,b)]. I.e., [e_0, e_1, e_2].
  4. Unravel. [[e_0, e_1, e_2]]. Notice now that [e_0, e_1] has been picked up by r_0 and [e_2] by r_1.
  5. Reshape. [[e_0, e_1, e_2]].

The solution is a bi-dimensional, 1x3 array:

| 0 1 2 |

Explanation

  1. Align recursively adds a new dimension in the array with lower dimensionality.
  2. Ravel recursively removes a dimension by converting elements into tuples.
  3. SQL Join operation: Cartesian product plus match.
  4. Unravel performs the inverse of 2.
  5. Reshape converts it to the indexer's dimensionality.
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  357156174
Powered by Datasette · Queries took 0.593ms · About: xarray-datasette