oneflow.zeros

oneflow.zeros(*size: Union[int, Tuple[int, ], oneflow.Size, List[int]], dtype: Optional[oneflow._oneflow_internal.dtype] = None, device: Optional[Union[oneflow._oneflow_internal.device, str]] = None, placement: Optional[oneflow._oneflow_internal.placement] = None, sbp: Optional[Union[oneflow._oneflow_internal.sbp.sbp, List[oneflow._oneflow_internal.sbp.sbp]]] = None, requires_grad: bool = False)

Returns a tensor filled with the scalar value 0, with the shape defined by the variable argument size.

Parameters
  • size (an integer or tuple of integer values) – a variable number of arguments or a collection like a list or tuple.

  • dtype (flow.dtype, optional) – the desired data type of returned tensor.

  • device (flow.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type

  • placement (flow.placement, optional) – the desired placement of returned global tensor. Default: if None, the returned tensor is local one using the argument device.

  • sbp (flow.sbp.sbp or tuple of flow.sbp.sbp, optional) – the desired sbp descriptor of returned global tensor. Default: if None, the returned tensor is local one using the argument device.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

For example:

>>> import oneflow as flow
>>> y = flow.zeros(5)
>>> y
tensor([0., 0., 0., 0., 0.], dtype=oneflow.float32)
>>> y = flow.zeros(2,3)
>>> y
tensor([[0., 0., 0.],
        [0., 0., 0.]], dtype=oneflow.float32)