qp.math.ones_like¶
- ones_like(tensor, dtype=None)[source]¶
Returns a tensor of all ones with the same shape and dtype as the input tensor.
- Parameters:
tensor (tensor_like) – input tensor
dtype (str, np.dtype, None) – The desired output datatype of the array. If not provided, the dtype of
tensoris used. This argument can be any supported NumPy dtype representation, including a string ("float64"), anp.dtypeobject (np.dtype("float64")), or a dtype class (np.float64). Iftensoris not a NumPy array, the equivalent dtype in the dispatched framework is used.
- Returns:
an all-ones tensor with the same shape and size as
tensor- Return type:
tensor_like
Example
>>> x = torch.tensor([1., 2.]) >>> ones_like(x) tensor([1., 1.]) >>> y = torch.tensor([[0], [5]]) >>> ones_like(y, dtype=np.complex128) tensor([[1.+0.j], [1.+0.j]], dtype=torch.complex128)