April 9, 2024, 11:13 p.m. | Super Kai (Kazuya Ito)

DEV Community dev.to

zeros() can create a 1D or more D tensor filled with zero or more 0., 0, 0.+0.j or False as shown below:


*Memos:




  • zeros() can be used only from torch but not from a tensor.

  • The default type is float32.



import torch

torch.zeros(0)
torch.zeros((0,))
# tensor([])

torch.zeros(3)
torch.zeros((3,))
# tensor([0., 0., 0.])

torch.zeros(3, 2)
torch.zeros((3, 2))
# tensor([[0., 0.], [0., 0.], [0., 0.]])

torch.zeros(3, 2, 4)
torch.zeros((3, 2, 4))
# tensor([[[0., 0., 0., 0.], [0., 0., 0., 0.]],
# [[0., …

false import memos ones pytorch tensor torch type zeros

Data Architect

@ University of Texas at Austin | Austin, TX

Data ETL Engineer

@ University of Texas at Austin | Austin, TX

Lead GNSS Data Scientist

@ Lurra Systems | Melbourne

Senior Machine Learning Engineer (MLOps)

@ Promaton | Remote, Europe

C003549 Data Analyst (NS) - MON 13 May

@ EMW, Inc. | Braine-l'Alleud, Wallonia, Belgium

Marketing Decision Scientist

@ Meta | Menlo Park, CA | New York City