問題文
A developer needs a new tensor of zeros with the same shape, dtype, and device as an existing tensor x. Which call expresses that most directly?
選択肢
- torch.zeros(x.shape), which is documented to inherit the dtype and the device of the tensor whose shape was passed in as the argument.
- x.fill_(0), which produces a new tensor of zeros with the same shape and dtype.
- x.zero(), so the zero tensor is built from the shape of x and nothing else.
- torch.zeros_like(x), which copies the shape, dtype, and device of x.