本文簡要介紹 python 語言中 numpy.zeros
的用法。
用法:
numpy.zeros(shape, dtype=float, order='C', *, like=None)
返回給定形狀和類型的新數組,用零填充。
- shape: int 或整數元組
新數組的形狀,例如
(2, 3)
或2
。- dtype: 數據類型,可選
數組所需的數據類型,例如
numpy.int8
。默認為numpy.float64
。- order: {‘C’, ‘F’},可選,默認:‘C’
是否在內存中以行優先(C 風格)或列優先(Fortran-style)順序存儲多維數據。
- like: array_like
允許創建非 NumPy 數組的引用對象。如果作為
like
傳入的類似數組支持__array_function__
協議,則結果將由它定義。在這種情況下,它確保創建一個與通過此參數傳入的數組對象兼容的數組對象。
- out: ndarray
具有給定形狀、數據類型和順序的零數組。
參數:
返回:
例子:
>>> np.zeros(5) array([ 0., 0., 0., 0., 0.])
>>> np.zeros((5,), dtype=int) array([0, 0, 0, 0, 0])
>>> np.zeros((2, 1)) array([[ 0.], [ 0.]])
>>> s = (2,2) >>> np.zeros(s) array([[ 0., 0.], [ 0., 0.]])
>>> np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype array([(0, 0), (0, 0)], dtype=[('x', '<i4'), ('y', '<i4')])
相關用法
- Python numpy zeros_like用法及代碼示例
- Python numpy RandomState.standard_exponential用法及代碼示例
- Python numpy hamming用法及代碼示例
- Python numpy legendre.legint用法及代碼示例
- Python numpy chararray.ndim用法及代碼示例
- Python numpy chebyshev.chebsub用法及代碼示例
- Python numpy chararray.nbytes用法及代碼示例
- Python numpy ma.indices用法及代碼示例
- Python numpy matrix.A1用法及代碼示例
- Python numpy MaskedArray.var用法及代碼示例
- Python numpy ma.zeros用法及代碼示例
- Python numpy broadcast用法及代碼示例
- Python numpy matrix.T用法及代碼示例
- Python numpy matrix.I用法及代碼示例
- Python numpy MaskedArray.T用法及代碼示例
- Python numpy hermite.hermfromroots用法及代碼示例
- Python numpy hermite_e.hermediv用法及代碼示例
- Python numpy recarray.dot用法及代碼示例
- Python numpy random.mtrand.RandomState.wald用法及代碼示例
- Python numpy trim_zeros用法及代碼示例
- Python numpy chebyshev.chebdiv用法及代碼示例
- Python numpy linalg.svd用法及代碼示例
- Python numpy copy用法及代碼示例
- Python numpy negative用法及代碼示例
- Python numpy ndarray.astype用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.zeros。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。