logo

Muestreo aleatorio en numpy | función randint()

numpy.random.randint()> es una de las funciones para realizar muestreo aleatorio en numpy. Devuelve una matriz de forma especificada y la llena con números enteros aleatorios desde bajo (inclusivo) hasta alto (exclusivo), es decir, en el intervalo [low, high).>

Sintaxis: numpy.random.randint(bajo, alto=Ninguno, tamaño=Ninguno, dtype=’l’)

Parámetros:
bajo : [int] Entero más bajo (con signo) que se extraerá de la distribución. Pero funciona como un entero más alto en la muestra si alto = Ninguno.
alto : [int, opcional] El entero más grande (con signo) que se extraerá de la distribución.
tamaño : [int o tupla de enteros, opcional] Forma de salida. Si la forma dada es, por ejemplo, (m, n, k), entonces se extraen m * n * k muestras. El valor predeterminado es Ninguno, en cuyo caso se devuelve un valor único.
tipo de : [opcional] Tipo de datos de salida deseado.



Devolver : Matriz de números enteros aleatorios en el intervalo. [low, high)>o un único int aleatorio si no se proporciona el tamaño.

Código #1:




# Python program explaining> # numpy.random.randint() function> > # importing numpy> import> numpy as geek> > # output array> out_arr>=> geek.random.randint(low>=> 0>, high>=> 3>, size>=> 5>)> print> (>'Output 1D Array filled with random integers : '>, out_arr)>

>

>

Producción :

 Output 1D Array filled with random integers : [1 1 0 1 1]>

Código #2:




sistemas expertos

# Python program explaining> # numpy.random.randint() function> > # importing numpy> import> numpy as geek> > > # output array> out_arr>=> geek.random.randint(low>=> 4>, size>=>(>2>,>3>))> print> (>'Output 2D Array filled with random integers : '>, out_arr)>

>

>

Producción :

 Output 2D Array filled with random integers : [[1 1 0] [1 0 3]]>


Código #3:




# Python program explaining> # numpy.random.randint() function> > # importing numpy> import> numpy as geek> > # output array> out_arr>=> geek.random.randint(>2>,>10>, (>2>,>3>,>4>))> print> (>'Output 3D Array filled with random integers : '>, out_arr)>

>

>

Producción :

 Output 3D Array filled with random integers : [[[4 8 5 7] [6 5 6 7] [4 3 4 3]] [[2 9 2 2] [3 2 2 3] [6 8 3 2]]]>