Write a NumPy program to create an array of 4,5 shape and swap column1 with column4.
import numpy as np array_nums = np.arange(20).reshape(4,5) print("Original array:") print(array_nums) print("\nAfter swapping column1 with column4:") array_nums[:,[0,3]] = array_nums[:,[3,0]] print(array_nums)
Sample Output:
Original array: [[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19]] After swapping column1 with column4: [[ 3 1 2 0 4] [ 8 6 7 5 9] [13 11 12 10 14] [18 16 17 15 19]]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer