소스 뷰어
조회수 :   1
# 벡터 내적

import numpy as np

# 두 벡터
a = np.array( [1, 2, 3] )
b = np.array( [4, 5, 6] )

# 아인슈타인 표기법을 사용한 내적 계산
dot_product = np.einsum('i,i->', a, b)
# 위 식에서 'i,i->'는 두 벡터의 동일한 인덱스를 곱하고,
# 결과를 스칼라로 반환하라는 의미입니다.

print( "a = ", a )
print( "b = ", b )
print("Dot product einstein sum =", dot_product)
print("Dot product a@b =", a@b )
a =  [1 2 3]
b =  [4 5 6]
Dot product einstein sum = 32
Dot product a@b = 32