numpy.empty创建指定形状和dtype的未初始化数组
numpy.empty(shape, dtype = float, order = 'C')
构造器接受下列参数:
序号 参数及描述
- Shape 空数组的形状,整数或整数元组
- Dtype 所需的输出数组类型,可选
- Order 'C’为按行的 C 风格数组,'F’为按列的 Fortran 风格数组
例: 数组元素为随机值
import numpy as np
arr = np.empty((3,3),dtype = 'i1')
print(arr)
例
#numpy.zeros
#返回特定大小,以0填充
arr = np.zeros((3,3))
print(arr)
自定义类型
arr = np.zeros((3,3), dtype = [(‘x’, ‘i4’), (‘y’, ‘i4’)])
print(arr)