Q:

Write a NumPy program to create an array of 4,5 shape and swap column1 with column4

0

Write a NumPy program to create an array of 4,5 shape and swap column1 with column4.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now