Write a NumPy program to split of an array of shape 4x4 it into two arrays along the second axis.Sample array :[[ 0 1 2 3][ 4 5 6 7][ 8 9 10 11][12 13 14 15]]
import numpy as np x = np.arange(16).reshape((4, 4)) print("Original array:",x) print("After splitting horizontally:") print(np.hsplit(x, [2, 6]))
Sample Output:
Original array: [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11] [12 13 14 15]] After splitting horizontally: [array([[ 0, 1], [ 4, 5], [ 8, 9], [12, 13]]), array([[ 2, 3], [ 6, 7], [10, 11], [14, 15]]), array([], shape=(4, 0), dtype=int64)]
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