Write a NumPy program to split a given array into multiple sub-arrays vertically (row-wise).
import numpy as np print("\nOriginal arrays:") x = np.arange(16.0).reshape(4, 4) print(x) new_array1 = np.vsplit(x, 2) print("\nSplit an array into multiple sub-arrays vertically:") print(new_array1)
Sample Output:
Original arrays: [[ 0. 1. 2. 3.] [ 4. 5. 6. 7.] [ 8. 9. 10. 11.] [12. 13. 14. 15.]] Split an array into multiple sub-arrays vertically: [array([[0., 1., 2., 3.], [4., 5., 6., 7.]]), array([[ 8., 9., 10., 11.], [12., 13., 14., 15.]])]
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