numpy

numpy,第1张

numpy

  numpy的random用于生成随机数。

randint

  randint用于生成随机整数

import numpy as np

# 生成[0, 9)之间的随机整数矩阵,大小为(3, 3)
a = np.random.randint(9, size=(3, 3))
print("a =", a)
# 生成5个[0, 2)之间的整数
b = np.random.randint(0, 2, 5)
print("b =", b)

执行结果:

a = [[3 7 1]
 [1 2 8]
 [2 4 7]]
b = [1 0 1 0 0]

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5689445.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存