HackerRank-Python
Prepare > Python > Numpy > Inner and Outer
stem_sw
2023. 9. 7. 19:28
Inner and Outer | HackerRank
Use NumPy to find the inner and outer product of arrays.
www.hackerrank.com
문제
Task
You are given two arrays: A and B.
Your task is to compute their inner and outer product.
Input Format
The first line contains the space separated elements of array A.
The second line contains the space separated elements of array B.
Output Format
First, print the inner product.
Second, print the outer product.
=> array A와 B를 줄건데 내적하고 외적해라
코드
import numpy as np
A = np.array(input().split(), int)
B = np.array(input().split(), int)
print(np.inner(A,B))
print(np.outer(A,B))
노트
np.inner()
import numpy
A = numpy.array([0, 1])
B = numpy.array([3, 4])
print(numpy.inner(A, B)) #Output : 4
- 두 array를 내적함
- 두 열벡터를 내적하면 결과로 스칼라값이 나옴
np.outer()
import numpy
A = numpy.array([0, 1])
B = numpy.array([3, 4])
print(numpy.outer(A, B))
"""
Output
[[0 0]
[3 4]]
"""
- 두 array를 외적함
- 두 열벡터를 외적하면 결과로 행렬(matrix)가 나옴
참조
외적 - 위키백과, 우리 모두의 백과사전
위키백과, 우리 모두의 백과사전. 이 문서는 벡터끼리 곱하면 행렬을 얻게 되는 ‘외적’(outer product)에 관한 것입니다. 벡터끼리 곱하면 벡터를 얻게 되는 ‘외적’(cross product)에 대해서는 벡터
ko.wikipedia.org
[기하학 (Geometry)] 내적 (Inner Product) 란?
내적은 영어로 다양하게 불리는데 Inner product 라고도 하고, dot product, scalar product 라고도 불린...
blog.naver.com