python中numpy.zeros(np.zeros)的使用方法
翻譯:
用法:zeros(shape, dtype=float, order='C')
返回:返回來一個(gè)給定形狀和類型的用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,浮點(diǎn)數(shù),f8(64位)
c,浮點(diǎn)負(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)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python實(shí)現(xiàn)普通圖片轉(zhuǎn)ico圖標(biāo)的方法詳解
ICO是一種圖標(biāo)文件格式,圖標(biāo)文件可以存儲單個(gè)圖案、多尺寸、多色板的圖標(biāo)文件。本文將利用Python實(shí)現(xiàn)普通圖片轉(zhuǎn)ico圖標(biāo),感興趣的小伙伴可以了解一下2022-11-11
matplotlib自定義鼠標(biāo)光標(biāo)坐標(biāo)格式的實(shí)現(xiàn)
這篇文章主要介紹了matplotlib自定義鼠標(biāo)光標(biāo)坐標(biāo)格式的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
Django使用list對單個(gè)或者多個(gè)字段求values值實(shí)例
這篇文章主要介紹了Django使用list對單個(gè)或者多個(gè)字段求values值實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Python?hashlib模塊與哈希算法保護(hù)數(shù)據(jù)完整性教程
hashlib模塊為Python提供了一種簡便的方式來使用各種哈希算法,如MD5、SHA-1、SHA-256等,哈希函數(shù)廣泛用于密碼學(xué)、數(shù)據(jù)完整性驗(yàn)證和安全存儲等領(lǐng)域2024-01-01
Python實(shí)現(xiàn)帶參數(shù)的用戶驗(yàn)證功能裝飾器示例
這篇文章主要介紹了Python實(shí)現(xiàn)帶參數(shù)的用戶驗(yàn)證功能裝飾器,結(jié)合實(shí)例形式分析了Python用戶驗(yàn)證裝飾器具體定義及使用技巧,需要的朋友可以參考下2018-12-12

