>>> np.zeros((3,4))
array([[0.,0.,0.,0.],[0.,0.,0.,0.],[0.,0.,0.,0.]])>>> np.ones((2,3,4), dtype=np.int16 )# dtype can also be specified
array([[[1,1,1,1],[1,1,1,1],[1,1,1,1]],[[1,1,1,1],[1,1,1,1],[1,1,1,1]]], dtype=int16)>>> np.empty((2,3))# uninitialized, output may vary
array([[3.73603959e-262,6.02658058e-154,6.55490914e-260],[5.30498948e-313,3.14673309e-307,1.00000000e+000]])
为了创建数字组成的数组,NumPy提供了一个类似于range的函数,该函数返回数组而不是列表。
>>> np.arange(10,30,5)
array([10,15,20,25])>>> np.arange(0,2,0.3)# it accepts float arguments
array([0.,0.3,0.6,0.9,1.2,1.5,1.8])