您的位置:首页 > 编程语言 > Python开发

numpy.zeros_like

2017-06-03 09:41 387 查看

numpy.zeros_like

numpy.zeros_like(a,dtype=None,
order='K', subok=True)[source]
Return an array of zeros with the same shape and type as a given array.

Parameters:a : array_like

The shape and data-type of
a define these same attributes ofthe returned array.

dtype : data-type, optional

Overrides the data type of the result.

New in version 1.6.0.

order : {‘C’, ‘F’, ‘A’, or ‘K’}, optional

Overrides the memory layout of the result. ‘C’ means C-order,‘F’ means F-order, ‘A’ means ‘F’ ifa is Fortran contiguous,‘C’ otherwise. ‘K’ means match the layout ofa
as closelyas possible.

New in version 1.6.0.

subok : bool, optional.

If True, then the newly created array will use the sub-classtype of ‘a’, otherwise it will be a base-class array. Defaultsto True.

Returns:out : ndarray

Array of zeros with the same shape and type as
a.

See also
ones_likeReturn an array of ones with shape and type of input.empty_likeReturn an empty array with shape and type of input.zerosReturn a new array setting values to zero.onesReturn a new array setting values to one.emptyReturn a new uninitialized array.
Example
c45d
s

>>>
>>> x = np.arange(6)
>>> x = x.reshape((2, 3))
>>> x
array([[0, 1, 2],
[3, 4, 5]])
>>> np.zeros_like(x)
array([[0, 0, 0],
[0, 0, 0]])


>>>
>>> y = np.arange(3, dtype=np.float)
>>> y
array([ 0.,  1.,  2.])
>>> np.zeros_like(y)
array([ 0.,  0.,  0.])
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: