Put the index as a whole:
a[[x, y]] = a[[y, x]]
With your example:
a = np.array([[4,3,1], [5,7,0], [9,9,3], [8,2,4]])
a
# array([[4, 3, 1],
# [5, 7, 0],
# [9, 9, 3],
# [8, 2, 4]])
a[[0, 2]] = a[[2, 0]]
a
# array([[9, 9, 3],
# [5, 7, 0],
# [4, 3, 1],
# [8, 2, 4]])
Related Contents:
- What is the difference between np.array() and np.asarray()?
- Concatenating two one-dimensional NumPy arrays
- NumPy array initialization (fill with identical values)
- Understanding NumPy’s einsum
- How do I create a numpy array of all True or all False?
- Replace all elements of Python NumPy Array that are greater than some value
- How to normalize a NumPy array to within a certain range?
- How to copy a 2D array into a 3rd dimension, N times?
- Numpy `logical_or` for more than two arguments
- Replacing Numpy elements if condition is met
- Is there any numpy group by function?
- How does NumPy’s transpose() method permute the axes of an array?
- Convert 2d numpy array into list of lists [duplicate]
- List to array conversion to use ravel() function
- Ambiguity in Pandas Dataframe / Numpy Array “axis” definition
- Interweaving two numpy arrays
- How to create a numpy array of arbitrary length strings?
- Python: Differentiating between row and column vectors
- Why are NumPy arrays so fast?
- Why is numpy’s einsum faster than numpy’s built in functions?
- Formatting floats in a numpy array [duplicate]
- Rearrange columns of numpy 2D array
- Most efficient way to forward-fill NaN values in numpy array
- NumPy array slice using None
- Create a two-dimensional array with two one-dimensional arrays
- array.array versus numpy.array
- 1D numpy concatenate: TypeError: only integer scalar arrays can be converted to a scalar index [duplicate]
- Numpy: For every element in one array, find the index in another array
- What are the advantages of using numpy.identity over numpy.eye?
- Get the column names of a python numpy ndarray
- How to check if a variable is either a python list, numpy array or pandas series
- Getting the indices of several elements in a NumPy array at once
- How do I remove all zero elements from a NumPy array?
- Generating a dense matrix from a sparse matrix in numpy python
- TypeError: Invalid dimensions for image data when plotting array with imshow()
- output of numpy.where(condition) is not an array, but a tuple of arrays: why?
- How does the axis parameter from NumPy work?
- How to overwrite array inside h5 file using h5py
- Converting int arrays to string arrays in numpy without truncation
- Copy numpy array into part of another array
- ValueError: shape mismatch: objects cannot be broadcast to a single shape
- Randomly select from numpy array
- Python Numpy TypeError: ufunc ‘isfinite’ not supported for the input types
- Numpy list of 1D Arrays to 2D Array
- Element-wise string concatenation in numpy
- Numpy Vector (N,1) dimension -> (N,) dimension conversion
- Modify a particular row/column of a NumPy array
- Reshape an array in NumPy
- Append 2D array to 3D array, extending third dimension
- Sending a C++ array to Python and back (Extending C++ with Numpy)