numpy Задать матрицу случайных чисел указанного размера -- numpy.random.randint пример кода

Получим матрицу размерностью 4x3х5 со случайными значениями в диапазоне от 0 до 100:

import numpy as np  # импортируем нампай и назначаем псевдоним

a = np.random.randint(0, 100, (4, 5, 3))
print('a==', a)

Документация

Общий вид вызова:

numpy.random.randint(low, high=None, size=None, dtype='l')

Параметры:

  • low: int
    Lowest (signed) integer to be drawn from the distribution (unless high=None, in which case this parameter is the highest such integer).
  • high : int, optional

    If provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if high=None).

  • size : int or tuple of ints, optional

    Параметр size задаёт:

    1. размерность матрицы (число элементов в передаваемом кортеже, в примере выше их три),
    2. и конкретную её форму (значения элементов кортежа).

    Так, например, кортеж (m, n, k), задаст матрицу рамерами m * n * k. Значение по умолчанию None, при котором возвращается единственное значение.

  • dtype : dtype, optional

    Desired dtype of the result. All dtypes are determined by their name, i.e., ‘int64’, ‘int’, etc, so byteorder is not available and a specific precision may have different C types depending on the platform. The default value is ‘np.int’.

Возвращаемые значения:

  • out: int or ndarray of ints
    size-shaped array of random integers from the appropriate distribution, or a single such random int if size not provided.

Источник:
https://docs.scipy.org/doc/numpy/referen...

Key Words for FKN + antitotal forum (CS VSU):