python中numpy.zeros(np.zeros)的使用方法
翻譯:
用法:zeros(shape, dtype=float, order='C')
返回:返回來一個給定形狀和類型的用0填充的數(shù)組;
參數(shù):shape:形狀
dtype:數(shù)據(jù)類型,可選參數(shù),默認(rèn)numpy.float64
dtype類型:
t ,位域,如t4代表4位
b,布爾值,true or false
i,整數(shù),如i8(64位)
u,無符號整數(shù),u8(64位)
f,浮點數(shù),f8(64位)
c,浮點負(fù)數(shù),
o,對象,
s,a,字符串,s24
u,unicode,u24
order:可選參數(shù),c代表與c語言類似,行優(yōu)先;F代表列優(yōu)先
例子:
np.zeros(5) array([ 0., 0., 0., 0., 0.]) np.zeros((5,), dtype=np.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')]) ######################################################## zeros(shape, dtype=float, order='C') Return a new array of given shape and type, filled with zeros. Parameters ---------- shape : int or sequence of ints Shape of the new array, e.g., ``(2, 3)`` or ``2``. dtype : data-type, optional The desired data-type for the array, e.g., `numpy.int8`. Default is `numpy.float64`. order : {'C', 'F'}, optional Whether to store multidimensional data in C- or Fortran-contiguous (row- or column-wise) order in memory. Returns ------- out : ndarray Array of zeros with the given shape, dtype, and order. See Also -------- zeros_like : Return an array of zeros with shape and type of input. ones_like : Return an array of ones with shape and type of input. empty_like : Return an empty array with shape and type of input. ones : Return a new array setting values to one. empty : Return a new uninitialized array. Examples -------- np.zeros(5) array([ 0., 0., 0., 0., 0.]) np.zeros((5,), dtype=np.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')]) Type: builtin_function_or_method
以上這篇python中numpy.zeros(np.zeros)的使用方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python中單例常用的幾種實現(xiàn)方法總結(jié)
Python 的模塊就是天然的單例模式,下面這篇文章主要給大家介紹了關(guān)于python中單例常用的幾種實現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用python單例具有一定的參考學(xué)習(xí)價值,需要的朋友們一起來看看吧2018-10-10python如何實現(xiàn)wifi自動連接,解決電腦wifi經(jīng)常斷開問題
這篇文章主要介紹了python實現(xiàn)wifi自動連接,解決電腦wifi經(jīng)常斷開的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06python for循環(huán)內(nèi)輸出和外輸出方式
這篇文章主要介紹了python for循環(huán)內(nèi)輸出和外輸出方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03Python read函數(shù)按字節(jié)(字符)讀取文件的實現(xiàn)
這篇文章主要介紹了Python read函數(shù)按字節(jié)(字符)讀取文件的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07