numpy.empty
创建指定形状和dtype的未初始化数组
numpy.empty(shape, dtype = float, order = 'C')
-
Shape 空数组的形状,整数或整数元组
-
Dtype 所需的输出数组类型,可选
-
Order 'C’为按行的 C 风格数组,'F’为按列的 Fortran 风格数组
下面的代码展示空数组的例子,因为它们未初始化,所以数组元素默认为 0
In [1]: import numpy as np
In [2]: num = np.empty([3,2], dtype=int)
In [3]: num
Out[3]:
array([[0, 0],
[0, 0],
[0, 0]])
numpy.zeros
返回特定大小,以 0 填充的新数组
numpy.zeros(shape, dtype = float, order = 'C')
In [4]: num = np.zeros(5)
In [5]: num
Out[5]: array([0., 0., 0., 0., 0.])
In [6]: sum = np.zeros((5,), dtype=np.int)
In [7]: sum
Out[7]: array([0, 0, 0, 0, 0])
numpy.ones
返回特定大小,以 1 填充的新数组
numpy.ones(shape, dtype = None, order = 'C')
In [8]: num = np.ones(5)
In [9]: num
Out[9]: array([1., 1., 1., 1., 1.])
In [10]: num = np.ones([2,2], dtype=int)
In [11]: num
Out[11]:
array([[1, 1],
[1, 1]])