ones_like

sparse.ones_like(a, dtype=None, format=None, compressed_axes=None)[source]

Return a SparseArray of ones with the same shape and type as a.

Parameters
  • a (array_like) – The shape and data-type of the result will match those of a.

  • dtype (data-type, optional) – Overrides the data type of the result.

  • format (str, optional) – A format string.

  • compressed_axes (iterable, optional) – The axes to compress if returning a GCXS array.

Returns

out – Array of ones with the same shape and type as a.

Return type

SparseArray

Examples

>>> x = np.ones((2, 3), dtype='i8')
>>> ones_like(x).todense()  
array([[1, 1, 1],
       [1, 1, 1]])