np.random.randint

np.random.randint 是 Numpy 库中的一个函数,用于生成随机整数。该函数的用法如下:

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

其中:

  • low:生成的随机整数的下限(包含)
  • high:生成的随机整数的上限(不包含)
  • size:生成数组的形状
  • dtype:生成数组的数据类型

例如,以下代码生成一个长度为5的整数数组,元素的范围在0~100之间:

import numpy as np

np.random.randint(0, 100, size=5)

猜你喜欢

转载自blog.csdn.net/weixin_42601608/article/details/129574095