Return a new array of given shape and type, without initializing entries.
empty, unlike zeros, does not set the array values to zero, and may therefore be marginally faster. On the other hand, it requires the user to manually set all the values in the array, and should be used with caution.
numpy.empty
并不真正创建空数组。它创建了一个带有未初始化数据缓冲区的数组-数组的元素是内存中的任意垃圾。这不是随机的-它通常都是零,或者是最近释放的数组的内容,或者(可能是敏感的)来自其他一些最近释放的对象的数据。一个元素甚至可以是一个信号NaN,如果您试图使用它执行任何操作,它可能会使您的程序崩溃没有办法对此进行测试
您还指定了长度为零的维度。这使得数组实际上是空的,因为它没有元素。您可以使用
arr.size == 0
测试这一点Numpy文档称数组将被初始化为任意值。是的,将为条目分配内存
https://numpy.org/doc/1.18/reference/generated/numpy.empty.html
根据documentation报告:
如果您计划以任何方式写入所有值,那么它可能是
zeros
的替代方案相关问题 更多 >
编程相关推荐