tensor와 논리 연산

J. Hwang·2024년 8월 7일
0

논리 연산 (logical operation; boolean operation) 은 참, 거짓 두 가지의 원소만 존재하는 집합에서의 연산이다.

논리곱 (AND)

  • 입력된 신호가 모두 True 일 때 출력이 True 가 되는 연산
  • torch.logical_and(x, y)
x = torch.tensor([True, True, False, False])
y = torch.tensor([True, False, True, False])

result = torch.logical_and(x, y)     # tensor([True, False, False, False])

논리합 (OR)

  • 입력된 신호 중 하나라도 True 일 때 출력이 True 가 되는 연산
  • torch.logical_or(x, y)
x = torch.tensor([True, True, False, False])
y = torch.tensor([True, False, True, False])

result = torch.logical_or(x, y)     # tensor([True, True, True, False])

배타적 논리합 (XOR)

  • 입력된 신호 중 하나만 True 일 때 출력이 True 가 되는 연산
  • torch.logical_xor(x, y)
x = torch.tensor([True, True, False, False])
y = torch.tensor([True, False, True, False])

result = torch.logical_or(x, y)     # tensor([False, True, True, False])
profile
Let it code

0개의 댓글