Add broadcast function to the API#670
Merged
Merged
Conversation
Member
Author
|
Any comments? This needs a rebase, but is otherwise ready for review |
Contributor
There was a problem hiding this comment.
Can there be a test for broadcasting coordinates, not just data variables? That is something I use frequently, and I currently have to hack it (as in #649).
Member
Author
There was a problem hiding this comment.
I'll add some more explicit tests.
Member
|
LGTM. |
This is a renaming and update of the existing `xray.broadcast_arrays` function,
which now works properly in the light of GH648.
Examples
--------
Broadcast two data arrays against one another to fill out their dimensions:
>>> a = xray.DataArray([1, 2, 3], dims='x')
>>> b = xray.DataArray([5, 6], dims='y')
>>> a
<xray.DataArray (x: 3)>
array([1, 2, 3])
Coordinates:
* x (x) int64 0 1 2
>>> b
<xray.DataArray (y: 2)>
array([5, 6])
Coordinates:
* y (y) int64 0 1
>>> a2, b2 = xray.broadcast(a, b)
>>> a2
<xray.DataArray (x: 3, y: 2)>
array([[1, 1],
[2, 2],
[3, 3]])
Coordinates:
* x (x) int64 0 1 2
* y (y) int64 0 1
>>> b2
<xray.DataArray (x: 3, y: 2)>
array([[5, 6],
[5, 6],
[5, 6]])
Coordinates:
* y (y) int64 0 1
* x (x) int64 0 1 2
Fill out the dimensions of all data variables in a dataset:
>>> ds = xray.Dataset({'a': a, 'b': b})
>>> ds2, = xray.broadcast(ds) # use tuple unpacking to extract one dataset
>>> ds2
<xray.Dataset>
Dimensions: (x: 3, y: 2)
Coordinates:
* x (x) int64 0 1 2
* y (y) int64 0 1
Data variables:
a (x, y) int64 1 1 2 2 3 3
b (x, y) int64 5 6 5 6 5 6
shoyer
added a commit
that referenced
this pull request
Jan 1, 2016
Add broadcast function to the API
Member
Author
|
thanks for the feedback, guys! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a renaming and update of the existing
xray.broadcast_arraysfunction,which now works properly in the light of #648.
xref #649
cc @rabernat
Examples
Broadcast two data arrays against one another to fill out their dimensions:
Fill out the dimensions of all data variables in a dataset: