Linux 拨号vps windows公众号手机端

numpy随机生成整数怎么实现

lewis 8年前 (2017-01-21) 阅读数 10 #程序编程
文章标签 numpy

可以使用numpy.random.randint()函数来生成随机整数。

示例代码:

import numpy as np

# 生成一个1到10之间的随机整数
random_int = np.random.randint(1, 11)
print(random_int)

# 生成一个包含10个1到100之间的随机整数的数组
random_int_array = np.random.randint(1, 101, size=10)
print(random_int_array)

输出:

6
[35 13  5 73 33 52  4 78 62 81]
版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门