ones_like¶
-
ones_like(a)¶ Return an array of ones with the same shape and type as a given array.
Parameters: - a : ndarray
The shape and data-type of a define these same attributes of the returned array.
Returns: - out : ndarray
Array of ones with the same shape and type as a.
Examples
>>> x = np.arange(6) >>> x = x.reshape((2, 3)) >>> x array([[0., 1., 2.], [3., 4., 5.]]) >>> np.ones_like(x) array([[1., 1., 1.], [1., 1., 1.]])
>>> y = np.arange(3, dtype=float) >>> y array([0., 1., 2.], dtype=float64) >>> >>> np.ones_like(y) array([1., 1., 1.], dtype=float64)