=============random.randint的使用=======================
from numpy import random as pp x,y=pp.randint(0,10,size=(2,4)) print(x) print(y)
注:指定生成随机数的范围和生成随机数组的大小形式
运行结果:
[8 1 6 8]
[7 8 7 6]
from numpy import random as pp x,y,z=pp.randint(0,10,size=(3,4)) print(x) print(y) print(z)
运行结果:
[1 8 4 0]
[8 5 4 0]
[9 5 2 2]
===============需要对比一下=================
import numpy as np a,b,c=np.random.random((3,3)) print(a) print(b) print(c)生成的是小数多维数组
[ 0.91553294 0.7210993 0.91108758]
[ 0.3674479 0.41005686 0.76995569]
[ 0.59584865 0.69899946 0.86537229]
import numpy as np a,b,c=np.random.random(0,1,(3,3)) print(a) print(b) print(c)这样运行出错
================请跟第一节代码比较=========================
import numpy as np a,b,c=np.random.randint(0,10,size=[3,3]) #《-----()变为【】,照样运行 print(a) print(b) print(c)
请跟第一段代码比较。
======================================