728x90
numpy.dot() 은 numpy array를 곱할 때 사용한다.
1. 곱하는 두 행렬 A와 B가 1차원 행렬일 경우 각 자리수 끼리 곱해서 전부 더한다.
ex)
import numpy as np
a = np.array([1,2,3])
b = np.array([2,3,4])
print(np.dot(a,b))
=> 출력값 : 1*2 + 2*3 + 3*4 == 12
2. 곱하는 두 행렬 A, B가 2차원 행렬일 경우 일반적인 행렬 곱을 수행한다.
import numpy as np
def get_dot():
derivative = np.array([[-1, 0 , 1]])
blur = np.array([[1],[2],[1]])
x_dot = np.dot(blur, derivative)
y_dot = np.dot(derivative.T, blur.T)
return x_dot,y_dot
def get_oper():
derivative = np.array([[-1, 0, 1]])
blur = np.array([[1], [2], [1]])
x_oper = blur * derivative
y_oper = derivative.T * blur.T
return x_oper,y_oper
def main():
x_dot, y_dot = get_dot()
x_oper, y_oper = get_oper()
print('dot_x')
print(x_dot)
print('dot_y')
print(y_dot)
print('operation_x')
print(x_oper)
print("operation_y")
print(y_oper)
if __name__ == "__main__":
main();
728x90
'😒 저 저 저 개념없는 나 > 🔆 대파 있나요? Python' 카테고리의 다른 글
[ numpy | python] numpy.clip (0) | 2022.05.22 |
---|---|
[numpy | python] numpy.median (0) | 2022.05.22 |
[Python | numpy] numpy.mgrid() (0) | 2022.04.22 |
[Python | numpy] numpy.clip() (0) | 2022.04.17 |
[Python] 오류 발생 (operands could not be broadcast together with) (0) | 2022.04.03 |