numpy.empty()
Python numpy.empty(shape, dtype =float,order = ' C ')
:返回一个给定形状和类型的新数组,带有随机值。
参数:
-> shape : Number of rows
-> order : C_contiguous or F_contiguous
-> dtype : [optional, float(by Default)] Data type of returned array.
示例1
# Python Programming illustrating
# numpy.empty method
import numpy as geek
b = geek.empty(2, dtype = int)
print("Matrix b : \n", b)
a = geek.empty([2, 2], dtype = int)
print("\nMatrix a : \n", a)
c = geek.empty([3, 3])
print("\nMatrix c : \n", c)
输出:
Matrix b :
[ 0 1079574528]
Matrix a :
[[0 0]
[0 0]]
Matrix a :
[[ 0. 0. 0.]
[ 0. 0. 0.]
[ 0. 0. 0.]]
注意:与0不同,empty不会将数组值设置为0,因此可能稍微快一些。