Answers for "numpy shuffle"

3

randomly shuffle array python

import random
l = list(range(5))
print(l)
# [0, 1, 2, 3, 4]

lr = random.sample(l, len(l))
print(lr)
# [3, 2, 4, 1, 0]

print(l)
# [0, 1, 2, 3, 4]
Posted by: Guest on June-17-2020
0

shuffle array python

import random
random.shuffle(array)
Posted by: Guest on August-30-2021
0

Python shuffle array

import random
new_array = random.sample( array, len(array) )
Posted by: Guest on July-21-2021
0

numpy randomly swap lines

>>> X = np.random.random((6, 2))
>>> X
array([[ 0.9818058 ,  0.67513579],
       [ 0.82312674,  0.82768118],
       [ 0.29468324,  0.59305925],
       [ 0.25731731,  0.16676408],
       [ 0.27402974,  0.55215778],
       [ 0.44323485,  0.78779887]])

>>> np.random.shuffle(X)
>>> X
array([[ 0.9818058 ,  0.67513579],
       [ 0.44323485,  0.78779887],
       [ 0.82312674,  0.82768118],
       [ 0.29468324,  0.59305925],
       [ 0.25731731,  0.16676408],
       [ 0.27402974,  0.55215778]])
Posted by: Guest on November-27-2020
0

np shuffle

arr = np.arange(10)
>>> np.random.shuffle(arr)
>>> arr
[1 7 5 2 9 4 3 6 0 8] # random
Posted by: Guest on November-18-2021

Python Answers by Framework

Browse Popular Code Answers by Language