Q:

Write a NumPy program to rearrange columns of a given numpy 2D array using given index positions

0

Write a NumPy program to rearrange columns of a given numpy 2D array using given index positions.

All Answers

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

import numpy as np
array1 = np.array([[11, 22, 33, 44, 55],
             [66,  77,  88,  99, 100]])
print("Original arrays:")
print(array1)
i = [1,3,0,4,2]
result = array1[:,i]
print("New array:")
print(result)

Sample Output:

Original arrays:
[[ 11  22  33  44  55]
 [ 66  77  88  99 100]]
New array:
[[ 22  44  11  55  33]
 [ 77  99  66 100  88]]

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