MCPcopy Create free account
hub / github.com/numpy/numpy / zeros_like

Function zeros_like

numpy/core/numeric.py:68–133  ·  view source on GitHub ↗

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 of the returned array. dtype : data-type, optional Overrides the data type of the res

(a, dtype=None, order='K', subok=True, shape=None)

Source from the content-addressed store, hash-verified

66
67@array_function_dispatch(_zeros_like_dispatcher)
68def zeros_like(a, dtype=None, order='K', subok=True, shape=None):
69 """
70 Return an array of zeros with the same shape and type as a given array.
71
72 Parameters
73 ----------
74 a : array_like
75 The shape and data-type of `a` define these same attributes of
76 the returned array.
77 dtype : data-type, optional
78 Overrides the data type of the result.
79
80 .. versionadded:: 1.6.0
81 order : {'C', 'F', 'A', or 'K'}, optional
82 Overrides the memory layout of the result. 'C' means C-order,
83 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
84 'C' otherwise. 'K' means match the layout of `a` as closely
85 as possible.
86
87 .. versionadded:: 1.6.0
88 subok : bool, optional.
89 If True, then the newly created array will use the sub-class
90 type of `a`, otherwise it will be a base-class array. Defaults
91 to True.
92 shape : int or sequence of ints, optional.
93 Overrides the shape of the result. If order='K' and the number of
94 dimensions is unchanged, will try to keep order, otherwise,
95 order='C' is implied.
96
97 .. versionadded:: 1.17.0
98
99 Returns
100 -------
101 out : ndarray
102 Array of zeros with the same shape and type as `a`.
103
104 See Also
105 --------
106 empty_like : Return an empty array with shape and type of input.
107 ones_like : Return an array of ones with shape and type of input.
108 full_like : Return a new array with shape of input filled with value.
109 zeros : Return a new array setting values to zero.
110
111 Examples
112 --------
113 >>> x = np.arange(6)
114 >>> x = x.reshape((2, 3))
115 >>> x
116 array([[0, 1, 2],
117 [3, 4, 5]])
118 >>> np.zeros_like(x)
119 array([[0, 0, 0],
120 [0, 0, 0]])
121
122 >>> y = np.arange(3, dtype=float)
123 >>> y
124 array([0., 1., 2.])
125 >>> np.zeros_like(y)

Callers 3

piecewiseFunction · 0.90
test_zerosMethod · 0.90
iscloseFunction · 0.70

Calls 2

empty_likeFunction · 0.70
zerosFunction · 0.50

Tested by 1

test_zerosMethod · 0.72