numpy.ones_like

numpy.ones_like(x[, out])

Returns an array of ones with the same shape and type as a given array.

Equivalent to a.copy().fill(1).

Please refer to the documentation for zeros_like for further details.

See also

zeros_like, ones

Examples

>>> a = np.array([[1, 2, 3], [4, 5, 6]])
>>> np.ones_like(a)
array([[1, 1, 1],
       [1, 1, 1]])

Previous topic

numpy.ones

Next topic

numpy.zeros

This Page