Return an array of ones with the same shape and type as a given array.
With default parameters, is equivalent to a.copy().fill(1).
Parameters : | a : array_like
dtype : data-type, optional
order : {‘C’, ‘F’, ‘A’, or ‘K’}, optional
|
---|---|
Returns : | out : ndarray
|
See also
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=np.float)
>>> y
array([ 0., 1., 2.])
>>> np.ones_like(y)
array([ 1., 1., 1.])