Numpy array_split()

Numpy

numpy.array_split(ary, indices_or_sections, axis=0)
Return broken array .
aryinput array to be broken
sectionsnumber, number of sections of output .

Examples

import numpy as np
my_ar=np.arange(9) 
print(np.array_split(my_ar,3))
Output
[array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8])]
With unequal number of elements in output
my_ar=np.arange(9) 
print(np.array_split(my_ar,5))
Output
[array([0, 1]), array([2, 3]), array([4, 5]), array([6, 7]), array([8])]
Example
import numpy as np
my_ar=np.arange(9) 
print(np.array_split(my_ar,4))
Output
[array([0, 1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]
my_data=np.array([[6, 3, 2], [7, 2, 2], [6, 2, 9]])
print(np.array_split(my_data,3))
Output
[array([[6, 3, 2]]), array([[7, 2, 2]]), array([[6, 2, 9]])]
Elements of the output array
import numpy as np
my_data=np.array([[6, 3, 2], [7, 2, 2], [6, 2, 9]])
my_ar=np.array_split(my_data,3)
print(my_ar[1])    # [[7 2 2]]
print(my_ar[1][0]) #  [7 2 2]
print(my_ar[1][0][2]) # 2
Using float dtype
my_ar=np.arange(9.) 
print(np.array_split(my_ar,4))
Output
[array([0., 1., 2.]), array([3., 4.]), array([5., 6.]), array([7., 8.])]
Numpy eye() ones() bincount()


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer