Sort object by labels or values (along an axis). Sorts the dataarray, either along specified dimensions, or according to values of 1-D dataarrays that share dimension with calling object. If the input variables are dataarrays, then the dataarrays are aligned
(
self,
variables: (
Hashable
| DataArray
| Sequence[Hashable | DataArray]
| Callable[[Self], Hashable | DataArray | Sequence[Hashable | DataArray]]
),
ascending: bool = True,
)
| 5228 | return computation.dot(self, other, dim=dim) |
| 5229 | |
| 5230 | def sortby( |
| 5231 | self, |
| 5232 | variables: ( |
| 5233 | Hashable |
| 5234 | | DataArray |
| 5235 | | Sequence[Hashable | DataArray] |
| 5236 | | Callable[[Self], Hashable | DataArray | Sequence[Hashable | DataArray]] |
| 5237 | ), |
| 5238 | ascending: bool = True, |
| 5239 | ) -> Self: |
| 5240 | """Sort object by labels or values (along an axis). |
| 5241 | |
| 5242 | Sorts the dataarray, either along specified dimensions, |
| 5243 | or according to values of 1-D dataarrays that share dimension |
| 5244 | with calling object. |
| 5245 | |
| 5246 | If the input variables are dataarrays, then the dataarrays are aligned |
| 5247 | (via left-join) to the calling object prior to sorting by cell values. |
| 5248 | NaNs are sorted to the end, following Numpy convention. |
| 5249 | |
| 5250 | If multiple sorts along the same dimension is |
| 5251 | given, numpy's lexsort is performed along that dimension: |
| 5252 | https://numpy.org/doc/stable/reference/generated/numpy.lexsort.html |
| 5253 | and the FIRST key in the sequence is used as the primary sort key, |
| 5254 | followed by the 2nd key, etc. |
| 5255 | |
| 5256 | Parameters |
| 5257 | ---------- |
| 5258 | variables : Hashable, DataArray, sequence of Hashable or DataArray, or Callable |
| 5259 | 1D DataArray objects or name(s) of 1D variable(s) in coords whose values are |
| 5260 | used to sort this array. If a callable, the callable is passed this object, |
| 5261 | and the result is used as the value for cond. |
| 5262 | ascending : bool, default: True |
| 5263 | Whether to sort by ascending or descending order. |
| 5264 | |
| 5265 | Returns |
| 5266 | ------- |
| 5267 | sorted : DataArray |
| 5268 | A new dataarray where all the specified dims are sorted by dim |
| 5269 | labels. |
| 5270 | |
| 5271 | See Also |
| 5272 | -------- |
| 5273 | Dataset.sortby |
| 5274 | numpy.sort |
| 5275 | pandas.sort_values |
| 5276 | pandas.sort_index |
| 5277 | |
| 5278 | Examples |
| 5279 | -------- |
| 5280 | >>> da = xr.DataArray( |
| 5281 | ... np.arange(5, 0, -1), |
| 5282 | ... coords=[pd.date_range("1/1/2000", periods=5)], |
| 5283 | ... dims="time", |
| 5284 | ... ) |
| 5285 | >>> da |
| 5286 | <xarray.DataArray (time: 5)> Size: 40B |
| 5287 | array([5, 4, 3, 2, 1]) |