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, …

check equal import memos pytorch tensor torch true

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

Sr. VBI Developer II

@ Atos | Texas, US, 75093

Wealth Management - Data Analytics Intern/Co-op Fall 2024

@ Scotiabank | Toronto, ON, CA