Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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]
Comment

PREVIOUS NEXT
Code Example
Python :: seeparate string without split function python 
Python :: <ipython-input-31-da456dc89cda in <module 
Python :: python list safely pop 
Python :: take space away from strings ion pyhton 
Python :: get length of a tuple in python 
Python :: pool does not print process id 
Python :: jupiter output 
Python :: check if entry is NaT] 
Python :: fetch api flask url redirect 
Python :: python geet second item in generator 
Python :: pyqt5 how to check if a push button is triggered 
Python :: how to detect the body with cv2 
Python :: torch.tensor.expand 
Python :: python generator for reading and writing file 
Python :: how to add to an index in a list in python 
Python :: client.futures exchange info() 
Python :: keep calm and carry on memes 
Python :: snipe cmd python.py 
Python :: python pass function as argument 
Python :: python code to open an application 
Python :: requests encoding python 
Python :: python inspect module 
Python :: pseudo code generator online python 
Python :: pyaudio 
Python :: global variable in python 
Python :: pytesseract.image_to 
Python :: python editor online 
Python :: pd.explode 
Python :: list comprehension odd numbers python 
Python :: how to convert int in python 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =