all AI news
equal(), eq() and ne() in PyTorch
April 14, 2024, 10:03 p.m. | Super Kai (Kazuya Ito)
DEV Community dev.to
equal() can check 2 tensors are the same:
*Memos:
equal() can be called both from torch and a tensor.- The tensors can be 0D or more D tensors.
import torch
tensor1 = torch.tensor([5, 9, 0, 1])
tensor2 = torch.tensor([5, 9, 0, 1])
torch.equal(tensor1, tensor2)
tensor1.equal(tensor2)
torch.equal(tensor2, tensor1)
tensor2.equal(tensor1)
# True
tensor1 = torch.tensor([5, 9, 0, 1])
tensor2 = torch.tensor([5., 9+0j, False, True])
torch.equal(tensor1, tensor2)
tensor1.equal(tensor2)
torch.equal(tensor2, tensor1)
tensor2.equal(tensor1)
# True
tensor1 = torch.tensor([5, 9, 0, 1])
tensor2 = torch.tensor([7, 9, …
More from dev.to / DEV Community
Jobs in AI, ML, Big Data
Artificial Intelligence – Bioinformatic Expert
@ University of Texas Medical Branch | Galveston, TX
Lead Developer (AI)
@ Cere Network | San Francisco, US
Research Engineer
@ Allora Labs | Remote
Ecosystem Manager
@ Allora Labs | Remote
Founding AI Engineer, Agents
@ Occam AI | New York
AI Engineer Intern, Agents
@ Occam AI | US