Write a Numpy program to split an array of 14 elements into 3 arrays, each of which has 2, 4, and 8 elements in the original order.Sample array: [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14]
import numpy as np x = np.arange(1, 15) print("Original array:",x) print("After splitting:") print(np.split(x, [2, 6]))
Sample Output:
Original array: [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14] After splitting: [array([1, 2]), array([3, 4, 5, 6]), array([ 7, 8, 9, 10, 11, 12, 13, 14])]
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