Q:

Write a NumPy program to split a given array into multiple sub-arrays vertically (row-wise)

0

Write a NumPy program to split a given array into multiple sub-arrays vertically (row-wise).

All Answers

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

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.]])]

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