Interchange two axes of an array. Parameters ---------- a : array_like Input array. axis1 : int First axis. axis2 : int Second axis. Returns ------- a_swapped : ndarray For NumPy >= 1.10.0, if `a` is an ndarray, then a view of `a
(a, axis1, axis2)
| 551 | |
| 552 | @array_function_dispatch(_swapaxes_dispatcher) |
| 553 | def swapaxes(a, axis1, axis2): |
| 554 | """ |
| 555 | Interchange two axes of an array. |
| 556 | |
| 557 | Parameters |
| 558 | ---------- |
| 559 | a : array_like |
| 560 | Input array. |
| 561 | axis1 : int |
| 562 | First axis. |
| 563 | axis2 : int |
| 564 | Second axis. |
| 565 | |
| 566 | Returns |
| 567 | ------- |
| 568 | a_swapped : ndarray |
| 569 | For NumPy >= 1.10.0, if `a` is an ndarray, then a view of `a` is |
| 570 | returned; otherwise a new array is created. For earlier NumPy |
| 571 | versions a view of `a` is returned only if the order of the |
| 572 | axes is changed, otherwise the input array is returned. |
| 573 | |
| 574 | Examples |
| 575 | -------- |
| 576 | >>> import numpy as np |
| 577 | >>> x = np.array([[1,2,3]]) |
| 578 | >>> np.swapaxes(x,0,1) |
| 579 | array([[1], |
| 580 | [2], |
| 581 | [3]]) |
| 582 | |
| 583 | >>> x = np.array([[[0,1],[2,3]],[[4,5],[6,7]]]) |
| 584 | >>> x |
| 585 | array([[[0, 1], |
| 586 | [2, 3]], |
| 587 | [[4, 5], |
| 588 | [6, 7]]]) |
| 589 | |
| 590 | >>> np.swapaxes(x,0,2) |
| 591 | array([[[0, 4], |
| 592 | [2, 6]], |
| 593 | [[1, 5], |
| 594 | [3, 7]]]) |
| 595 | |
| 596 | """ |
| 597 | return _wrapfunc(a, 'swapaxes', axis1, axis2) |
| 598 | |
| 599 | |
| 600 | def _transpose_dispatcher(a, axes=None): |
searching dependent graphs…