Python | numpy.array_split() method
With the help of numpy.array_split() method, we can get the splitted array of having different dimensions by using numpy.array_split() method.
Syntax :
numpy.array_split()Return : Return the splitted array of one dimension.
Example #1 :
In this example we can see that by using numpy.array_split() method, we are able to split the array in the number of subarrays by passing it as a parameter.
# import numpy import numpy as np array = np.arange(9) # using numpy.array_split() method gfg = np.array_split(array, 4) print(gfg) |
Output :
[array([0, 1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]
Example #2 :
# import numpy import numpy as np array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # using numpy.array_split() method gfg = np.array_split(array, 3) print(gfg) |
Output :
[array([[1, 2, 3]]), array([[4, 5, 6]]), array([[7, 8, 9]])]
Recommended Posts:
- class method vs static method in Python
- Python | os.dup() method
- Python | set() method
- Python | next() method
- Python | os.waitid() method
- Python | shutil.which() method
- Python PIL | getpalette() Method
- Python PIL | getcolors() Method
- Python | os.WIFEXITED() method
- Python | Tensorflow cos() method
- Python | os.major() method
- Python | os.stat() method
- Python | os.minor() method
- Python | os.fstat() method
- Python | os.umask() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



