-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transpose some but not all dimensions #1081
Comments
For what you want, I think |
Thanks, @shoyer I agree your methods works for 2d matrix, but for 3 or 4d matrix it fails. |
You need to provide the full list of dimensions to We could add a method like numpy's |
Thanks! I will check it. |
I have hit this issue before too.
|
Would that be consistent with |
I have also hit this issue, this method could be useful. I'm putting below my workaround in case it is any helpful: def reorder_dims(darray, dim1, dim2):
"""
Interchange two dimensions of a DataArray in a similar way as numpy's swap_axes
"""
dims = list(darray.dims)
assert set([dim1,dim2]).issubset(dims), 'dim1 and dim2 must be existing dimensions in darray'
ind1, ind2 = dims.index(dim1), dims.index(dim2)
dims[ind2], dims[ind1] = dims[ind1], dims[ind2]
return darray.transpose(*dims) |
What about allowing The implementation would simply reorder all the listed dimensions, keeping other dimensions in their original order. |
Though I think that would have radically different behavior for a 2-dim or 3-dim case. For the 2-dim case, it would enforce that order regardless of original order. For the 3-dim case, are you proposing they're swapped from their current order? (Maybe |
|
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
From personal experience I find that 99% of the time, I want to push some known dimensions either to the front or to the back of the array while I don't care about the order of the others. transpose(..., "x", "y") or transpose("x", "y", ...) where the ellipsis expands to all dimensions not explicitly listed, in their original order. There can be at most one ellipsis. |
Yes, this looks like a great use-case for Ellipsis!
…On Thu, Oct 10, 2019 at 2:12 AM crusaderky ***@***.***> wrote:
From personal experience I find that 99% of the time, I want to push some
known dimensions either to the front or to the back of the array while I
don't care about the order of the others.
I'd love to have this syntax:
transpose(..., "x", "y")
or
transpose("x", "y", ...)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1081?email_source=notifications&email_token=AAJJFVXRM73GZLFJYZXR6JDQN3WY7A5CNFSM4CVHGIYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEA3QQXQ#issuecomment-540477534>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJJFVW6IZJBW3KLMIU7IQDQN3WY7ANCNFSM4CVHGIYA>
.
|
There's one edge case that might be worth thinking carefully about here:
|
I would vote for (2), given it's fairly easy to replicate (1) by passing the full list, and I think (2) is arguably slightly more expected (NB this isn't how #3421 works now, but easy to change) |
I agree, I think (2) is what most users would expect. |
+1 for (2). Although user code that uses ... should not, by definition, care about the order of the variables that are not listed explicitly. |
Hi, all
Sorry to bother. Maybe it is a kind of stupid question for others, but I cannot figure it out at this moment.
I want to swap dims in xarray, like swapaxes in numpy. I found both dataarray and dataset has method
swap_dims
, but I don't understand its arguments:dims_dict : dict-like Dictionary whose keys are current dimension names and whose values are new names. Each value must already be a coordinate on this array.
Here is my example:
The error message:
Sorry to bother.
The text was updated successfully, but these errors were encountered: