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

Function PyArray_SwapAxes

numpy/core/src/multiarray/shape.c:637–662  ·  view source on GitHub ↗

NUMPY_API * SwapAxes */

Source from the content-addressed store, hash-verified

635 * SwapAxes
636 */
637NPY_NO_EXPORT PyObject *
638PyArray_SwapAxes(PyArrayObject *ap, int a1, int a2)
639{
640 PyArray_Dims new_axes;
641 npy_intp dims[NPY_MAXDIMS];
642 int n = PyArray_NDIM(ap);
643 int i;
644
645 if (check_and_adjust_axis_msg(&a1, n, npy_ma_str_axis1) < 0) {
646 return NULL;
647 }
648 if (check_and_adjust_axis_msg(&a2, n, npy_ma_str_axis2) < 0) {
649 return NULL;
650 }
651
652 for (i = 0; i < n; ++i) {
653 dims[i] = i;
654 }
655 dims[a1] = a2;
656 dims[a2] = a1;
657
658 new_axes.ptr = dims;
659 new_axes.len = n;
660
661 return PyArray_Transpose(ap, &new_axes);
662}
663
664
665/*NUMPY_API

Callers 1

array_swapaxesFunction · 0.85

Calls 3

PyArray_NDIMFunction · 0.85
PyArray_TransposeFunction · 0.85

Tested by

no test coverage detected