mars.tensor.ones_like#
- mars.tensor.ones_like(a, dtype=None, gpu=None, order='K')[源代码]#
Return a tensor of ones with the same shape and type as a given tensor.
- 参数
a (array_like) – The shape and data-type of a define these same attributes of the returned tensor.
dtype (data-type, optional) – Overrides the data type of the result.
gpu (bool, optional) – Allocate the tensor on GPU if True, None as default
order ({'C', 'F', 'A', or 'K'}, optional) – Overrides the memory layout of the result. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a as closely as possible.
- 返回
out – Tensor of ones with the same shape and type as a.
- 返回类型
Tensor
参见
zeros_like
Return a tensor of zeros with shape and type of input.
empty_like
Return a empty tensor with shape and type of input.
zeros
Return a new tensor setting values to zero.
ones
Return a new tensor setting values to one.
empty
Return a new uninitialized tensor.
实际案例
>>> import mars.tensor as mt
>>> x = mt.arange(6) >>> x = x.reshape((2, 3)) >>> x.execute() array([[0, 1, 2], [3, 4, 5]]) >>> mt.ones_like(x).execute() array([[1, 1, 1], [1, 1, 1]])
>>> y = mt.arange(3, dtype=float) >>> y.execute() array([ 0., 1., 2.]) >>> mt.ones_like(y).execute() array([ 1., 1., 1.])