문제
Every neuron starts with the same calculation: multiply each input by its weight and add everything up. That is the dot product of two vectors:
a · b = a₁×b₁ + a₂×b₂ + … + aₙ×bₙ
Implement dot_product(a, b).
Input
a, b: Two lists of numbers with the same length.
Output
Return the dot product as a decimal number.
제약 조건
1 ≤ length of a = length of b ≤ 1,000
-1,000 ≤ each value ≤ 1,000
예시
예시 1
입력:
a = [1.0, 2.0, 3.0]
b = [4.0, 5.0, 6.0]
예상 출력:
expected = 32.0
입력:
std::vector<double> a = {1.0, 2.0, 3.0};
std::vector<double> b = {4.0, 5.0, 6.0};
예상 출력:
double expected = 32.0;
입력:
double[] a = new double[] {1.0, 2.0, 3.0};
double[] b = new double[] {4.0, 5.0, 6.0};
예상 출력:
double expected = 32.0;
설명
1×4 + 2×5 + 3×6 = 4 + 10 + 18 = 32.
예시 2
입력:
a = [0.5, -1.5]
b = [2.0, 4.0]
예상 출력:
expected = -5.0
입력:
std::vector<double> a = {0.5, -1.5};
std::vector<double> b = {2.0, 4.0};
예상 출력:
double expected = -5.0;
입력:
double[] a = new double[] {0.5, -1.5};
double[] b = new double[] {2.0, 4.0};
예상 출력:
double expected = -5.0;
설명
0.5×2 + (-1.5)×4 = 1 - 6 = -5.
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.