Numpy 的 empty(~)
方法創建一個包含任意條目的新數組。這與 Numpy 的 zeros(~)
方法不同,zero(~)
方法用 0 初始化條目,而 empty(~)
則沒有初始化任何內容。
Performance-wise、empty()
比 zeros()
稍快,因為我們根本不初始化條目。
參數
1.shape
| int
或 array-like object
✜ Numpy 數組所需的形狀。提供 int
將返回一維展平數組。
2. dtype
| string
或 type
| optional
✜ Numpy 數組所需的數據類型。默認情況下,dtype=numpy.float64
。
返回值
填充任意值的數組,其形狀和類型由參數指定。
例子
創建一維 Numpy 數組
np.empty(3)
array([1.49166815e-154, 1.49166815e-154, 1.48219694e-323])
創建 int 類型的 Numpy 數組
np.empty(3, int)
array([2305843009213693952, 2305843009213693952, 3])
創建二維 Numpy 數組
使用元組
np.empty((2,3), int)
array([[0, 0, 0],
[0, 0, 0]])
使用數組:
np.empty([2,3], int)
array([[0, 0, 0],
[0, 0, 0]])
相關用法
- Python numpy matrix empty()用法及代碼示例
- Python email.message.Message.walk用法及代碼示例
- Python email.headerregistry.DateHeader用法及代碼示例
- Python email.message.EmailMessage.add_header用法及代碼示例
- Python emoji轉text用法及代碼示例
- Python email.utils.getaddresses用法及代碼示例
- Python email.header.decode_header用法及代碼示例
- Python email.message.EmailMessage.walk用法及代碼示例
- Python email.message.Message.add_header用法及代碼示例
- Python email.message.Message.as_bytes用法及代碼示例
- Python email.message.Message.as_string用法及代碼示例
- Python email.iterators._structure用法及代碼示例
- Python email.headerregistry.BaseHeader用法及代碼示例
- Python numpy matrix eye()用法及代碼示例
- Python enchant.request_dict()用法及代碼示例
- Python enum.IntEnum用法及代碼示例
- Python NumPy expandtabs方法用法及代碼示例
- Python math expm1()用法及代碼示例
- Python enchant.get_enchant_version()用法及代碼示例
- Python NumPy expand_dims方法用法及代碼示例
- Python enchant.request_pwl_dict()用法及代碼示例
- Python eval用法及代碼示例
- Python exponential轉float用法及代碼示例
- Python NumPy eye方法用法及代碼示例
- Python NumPy exp2方法用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | empty method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。