Answers for "random ordered slice of an array"

0

random ordered slice of an array

import random as rd
import numpy as np

mylist = list(np.linspace(0,50,50))
sliceSize = 3 # +1 below because python start counting frfom zero
result = mylist[rd.randrange(len(mylist)-sliceSize+1):][:sliceSize]
print(result)
Output: [6.122448979591837, 7.142857142857143, 8.16326530612245]
Posted by: Guest on October-11-2021

Python Answers by Framework

Browse Popular Code Answers by Language