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)
| 193 | |
| 194 | |
| 195 | def 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 |
no test coverage detected
searching dependent graphs…