ones¶
-
sparse.
ones
(shape, dtype=<class 'float'>, format='coo', compressed_axes=None)[source]¶ Return a SparseArray of given shape and type, filled with ones.
- Parameters
shape (int or tuple of ints) – Shape of the new array, e.g.,
(2, 3)
or2
.dtype (data-type, optional) – The desired data-type for the array, e.g., numpy.int8. Default is numpy.float64.
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 given shape and dtype.
- Return type
Examples
>>> ones(5).todense() array([1., 1., 1., 1., 1.])
>>> ones((2, 2), dtype=int).todense() array([[1, 1], [1, 1]])