numpy.empty使用方法

https://www.runoob.com/numpy/numpy-array-creation.html

https://docs.scipy.org/doc/numpy/reference/generated/numpy.empty.html

numpy.empty

Return a new array of given shape and type, without initializing entries.

返回 一个指定形状(shape)、数据类型(dtype)且未初始化的数组。

参数

  • shape
  • dtype
  • order

例子

1
2
3
4
import numpy as np
np.empty(4)


1
2
3
4
np.empty([2, 2])

# array([[1., 0.],
# [0., 1.]])
1
2
3
4
5
np.empty([3, 2], dtype=int)

# array([[-618601952, 346],
# [ 0, 0],
# [ 1, 0]])