Issue
I have a matrix
n = np.array([2,3,4,5,6,7])
I want to randomly split it to sublists of 2 elements like this:
new_array = [[2,5] ,[3,4] , [6,7]]
I tried:
s = np.array_split(n, 2)
but this only divide it into 2 sublist not a sublists of two elements )
Solution
Try:
n = np.array([2, 3, 4, 5, 6, 7])
np.random.shuffle(n)
print(np.array_split(n, n.shape[0] // 2))
Prints:
[array([5, 4]), array([7, 6]), array([2, 3])]
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.