mars.tensor.ones#

mars.tensor.ones(shape, dtype=None, chunk_size=None, gpu=None, order='C')[source]#

Return a new tensor of given shape and type, filled with ones.

Parameters
  • shape (int or sequence of ints) – Shape of the new tensor, e.g., (2, 3) or 2.

  • dtype (data-type, optional) – The desired data-type for the tensor, e.g., mt.int8. Default is mt.float64.

  • chunk_size (int or tuple of int or tuple of ints, optional) – Desired chunk size on each dimension

  • gpu (bool, optional) – Allocate the tensor on GPU if True, False as default

  • order ({'C', 'F'}, optional, default: C) – Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.

Returns

out – Tensor of ones with the given shape, dtype, and order.

Return type

Tensor

See also

zeros, ones_like

Examples

>>> import mars.tensor as mt
>>> mt.ones(5).execute()
array([ 1.,  1.,  1.,  1.,  1.])
>>> mt.ones((5,), dtype=int).execute()
array([1, 1, 1, 1, 1])
>>> mt.ones((2, 1)).execute()
array([[ 1.],
       [ 1.]])
>>> s = (2,2)
>>> mt.ones(s).execute()
array([[ 1.,  1.],
       [ 1.,  1.]])