all AI news
zeros(), zeros_like(), ones() and ones_like() in PyTorch
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., …
More from dev.to / DEV Community
Jobs in AI, ML, Big Data
Software Engineer for AI Training Data (School Specific)
@ G2i Inc | Remote
Software Engineer for AI Training Data (Python)
@ G2i Inc | Remote
Software Engineer for AI Training Data (Tier 2)
@ G2i Inc | Remote
Data Engineer
@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania
Artificial Intelligence – Bioinformatic Expert
@ University of Texas Medical Branch | Galveston, TX
Lead Developer (AI)
@ Cere Network | San Francisco, US