random.randint()与np.random.randint()的区别
一.比较两个函数 先来看看random.randint() import random for n in range(5 ): for i in range(10 ): print (random.randint(1,5),end= ' ' ) print () # 运行结果 1 5 5 3 3 1 3 1 5 2 4 4 4 4 4 4 3 1 5 2 3 2 3 1 1 5 5 1 4 3 3 4 4 2 5 5 3 4 4 4 3 5 4 5 4 5 4 5 2 4 Process finished with exit code 0 再来看看numpy.random.randint()方法: import numpy as np for n in range(5 ): for i in range(10 ): print (np.random.randint(1, 5), end= ' ' ) print () # 运行结果 2 4 1 1 1 1 2 2 2 4 3 4 3 2 3 4 3 2 2 4 2 2 1 2 1 1 3 3 3 4 4 1 4 2 4 1 3 4 3 2 2 3 3 2 3 4 4 3 4 4 Process finished with exit code 0 看出有什么不同了吗? random.randint()方法里面的取值区间是前闭后闭区间