MCPcopy
hub / github.com/pydata/xarray / permute_dims

Function permute_dims

xarray/namedarray/_array_api.py:195–221  ·  view source on GitHub ↗

Permutes the dimensions of an array. Parameters ---------- x : Array to permute. axes : Permutation of the dimensions of x. Returns ------- out : An array with permuted dimensions. The returned array must have the same data type as x

(x: NamedArray[Any, _DType], axes: _Axes)

Source from the content-addressed store, hash-verified

193
194
195def permute_dims(x: NamedArray[Any, _DType], axes: _Axes) -> NamedArray[Any, _DType]:
196 """
197 Permutes the dimensions of an array.
198
199 Parameters
200 ----------
201 x :
202 Array to permute.
203 axes :
204 Permutation of the dimensions of x.
205
206 Returns
207 -------
208 out :
209 An array with permuted dimensions. The returned array must have the same
210 data type as x.
211
212 """
213
214 dims = x.dims
215 new_dims = tuple(dims[i] for i in axes)
216 if isinstance(x._data, _arrayapi):
217 xp = _get_data_namespace(x)
218 out = x._new(dims=new_dims, data=xp.permute_dims(x._data, axes))
219 else:
220 out = x._new(dims=new_dims, data=x._data.transpose(axes)) # type: ignore[attr-defined]
221 return out

Callers 1

permute_dimsMethod · 0.90

Calls 4

_get_data_namespaceFunction · 0.85
permute_dimsMethod · 0.80
_newMethod · 0.45
transposeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…