본문 바로가기
Python

Numpy.dot

by 코딩하는 미토콘드리아 bioinformatics 2022. 1. 10.
반응형

np.dot( ) 함수를 사용해서

두 행렬의 내적(dot product)를 계산한다.

행렬 내적은 행렬의 곱이다.

 

두 행렬 A 와 B 의 내적은 왼쪽 행렬의 로우(행)와오른쪽 행렬의 컬럼(열)의 값들을 순차적으로 곱한 뒤그 값을 모두 더한 값이다. 

 

A 행렬과 B 행렬의 내적 연산인 np.dot(A, B) 의 결과 행렬의 1행 1열의 값인 58은 A행렬의 1행과 B행렬의 1열의 값들을 차례로곱한 값을 더한 것이다. 

1*7 + 2*9 + 3+11 = 58

이와 같이,1행 2열의 값인 64는 A행렬의 1행과 B행렬의 2열의 값들을 차례로곱한 값을 더한 것이다.

1*8 + 2*10 + 3+12 = 64

 

import numpy as np
A = np.array([[1,2,3,],
[4,5,6]])
B = np.array([[7,8],
[9,10],
[11,12]])

 

dot_product = np.dot(A, B)
print('행렬 내적 결과 :\n', dot_product)

[output]

행렬 내적 결과 :
[[ 58 64]
[139 154]]

 

추후에 다루겠지만

딥러닝에서 행렬의 곱으로 신경망 연산을 할 때

np.dot 함수가 꽤쓰이게 된다.

Reference

1.https://numpy.org/doc/stable/reference/generated/numpy.dot.html

 

numpy.dot — NumPy v1.22 Manual

Output argument. This must have the exact kind that would be returned if it was not used. In particular, it must have the right type, must be C-contiguous, and its dtype must be the dtype that would be returned for dot(a,b). This is a performance feature.

numpy.org

2. 파이썬 머신러닝 완벽가이드 위키북스 데이터 사이언스 시리즈

반응형

'Python' 카테고리의 다른 글

range 보다는 enumerate 를 사용하자  (0) 2022.01.17
Numpy.transpose  (0) 2022.01.10
Numpy.sort, argsort  (0) 2022.01.09
Numpy Fancy Indexing, Boolean Indexing  (0) 2022.01.06
Numpy 슬라이싱 (slicing)  (0) 2022.01.05