numpy.random.randint用法


numpy.random.randint用法

 

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

 

1

函数的作用是,返回一个随机整型数,范围从低(包括)到高(不包括),即[low, high)。

如果没有写参数high的值,则返回[0,low)的值。

 

参数如下:

 

low: int
生成的数值最低要大于等于low。(hign = None时,生成的数值要在[0, low)区间内)

 

high: int (可选)
如果使用这个值,则生成的数值在[low, high)区间。
size: int or tuple of ints(可选)

输出随机数的尺寸,比如size = (m * n* k)则输出同规模即m * n* k个随机数。默认是None的,仅仅返回满足要求的单一随机数。

 

dtype: dtype(可选):

想要输出的格式。如int64、int等等
输出:

out: int or ndarray of ints
返回一个随机数或随机数数组

 

例子

np.random.randint(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])

np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
1

np.random.randint(5, size=(2, 4))
array(4, 0, 2, 1], [3, 2, 2, 0)

np.random.randint(2, high=10, size=(2,3))
array(6, 8, 7], [2, 5, 2)

————————————————
版权声明:本文为CSDN博主「安ann」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011851421/java/article/details/83544853


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM