快速创建数组
import numpy as np
#使用random生成随机数组(随机的意思是同一行代码每次运行结果都会不同)
np.random.randn(10) #生成的是长度为10的一维数组,数组的元素符合标准正态分布
array([-2.01407771, -0.77011376, 0.48240321, 0.52711222, 1.87221082,
0.28280583, 0.89647812, -0.07944895, -0.10669309, -0.02220787])
np.random.randint(10) #生成一个随机的int,大小在0-10之间 ,每次运行得到不同的int值
8
np.random.randint(10,size=(2,3)) #其中10定义元素范围,size定义维数
array([[1, 3, 7],
[6, 4, 9]])
np.random.randint(10,size=20)
array([1, 5, 6, 3, 3, 7, 7, 1, 7, 6, 3, 6, 8, 1, 0, 1, 8, 2, 0, 1])
np.random.randint(10,size=20).reshape(4,5) #使用reshape进行重塑
array([[9, 0, 3, 9, 6],
[7, 0, 2, 6, 5],
[8, 7, 2,