Ejemplo 1: matriz aleatoria numpy
>>> np.random.rand(3,2)
array([[ 0.14022471, 0.96360618],
[ 0.37601032, 0.25528411],
[ 0.49313049, 0.94909878]])
>>> np.random.random_integers(low=0, high=9, size=(3,2))
array([[2, 3],
[2, 3],
[6, 3]])
Ejemplo 2: int aleatorio numpy
np.random.randint(2, size=10) # Creates binary sample of size 10
np.random.randint(5, size=10) # Creates sample with 0-4 as values of size 10
np.random.randint(5, size=(2, 4))
Ejemplo 3: generar python de matriz entera aleatoria
import numpy as np
randi_arr = np.random.randint(start, end, dimensions)
#random integers will be sampled from [start, end) (end not inclusive)
#end is optional; if end is not specified, random integers will be sampled from [0, start) (start not inclusive)
#dimensions can be specified as shown here; (m,n) #2D array with size 'm x n'
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)