MCPcopy Create free account
hub / github.com/numpy/numpy / swapaxes

Function swapaxes

numpy/core/fromnumeric.py:538–581  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

536
537@array_function_dispatch(_swapaxes_dispatcher)
538def swapaxes(a, axis1, axis2):
539 """
540 Interchange two axes of an array.
541
542 Parameters
543 ----------
544 a : array_like
545 Input array.
546 axis1 : int
547 First axis.
548 axis2 : int
549 Second axis.
550
551 Returns
552 -------
553 a_swapped : ndarray
554 For NumPy >= 1.10.0, if `a` is an ndarray, then a view of `a` is
555 returned; otherwise a new array is created. For earlier NumPy
556 versions a view of `a` is returned only if the order of the
557 axes is changed, otherwise the input array is returned.
558
559 Examples
560 --------
561 >>> x = np.array([[1,2,3]])
562 >>> np.swapaxes(x,0,1)
563 array([[1],
564 [2],
565 [3]])
566
567 >>> x = np.array([[[0,1],[2,3]],[[4,5],[6,7]]])
568 >>> x
569 array([[[0, 1],
570 [2, 3]],
571 [[4, 5],
572 [6, 7]]])
573
574 >>> np.swapaxes(x,0,2)
575 array([[[0, 4],
576 [2, 6]],
577 [[1, 5],
578 [3, 7]]])
579
580 """
581 return _wrapfunc(a, 'swapaxes', axis1, axis2)
582
583
584def _transpose_dispatcher(a, axes=None):

Callers 3

transposeFunction · 0.90
check_qr_stackedMethod · 0.90
_raw_fftFunction · 0.90

Calls 1

_wrapfuncFunction · 0.85

Tested by 1

check_qr_stackedMethod · 0.72