Q:

Write a NumPy program to split array into multiple sub-arrays along the 3rd axis

0

Write a NumPy program to split array into multiple sub-arrays along the 3rd axis.

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(2, 2, 4)
print(x)
new_array1 = np.dsplit(x, 2)
print("\nsplit array into multiple sub-arrays along the 3rd axis:")
print(new_array1)

Sample Output:

Original arrays:
[[[ 0.  1.  2.  3.]
  [ 4.  5.  6.  7.]]

 [[ 8.  9. 10. 11.]
  [12. 13. 14. 15.]]]

split array into multiple sub-arrays along the 3rd axis:
[array([[[ 0.,  1.],
        [ 4.,  5.]],

       [[ 8.,  9.],
        [12., 13.]]]), array([[[ 2.,  3.],
        [ 6.,  7.]],

       [[10., 11.],
        [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