Write a NumPy program to rearrange columns of a given numpy 2D array using given index positions.
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]]
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