물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Mean Square Error

BEstyle 2022. 11. 4. 13:19

DESCRIPTION:

Complete the function that

  • accepts two integer arrays of equal length
  • compares the value each member in one array to the corresponding member in the other
  • squares the absolute value difference between those two values
  • and returns the average of those squared absolute value difference between each member pair.

Examples

[1, 2, 3], [4, 5, 6]              -->   9   because (9 + 9 + 9) / 3
[10, 20, 10, 2], [10, 25, 5, -2]  -->  16.5 because (0 + 25 + 25 + 16) / 4
[-1, 0], [0, -1]                  -->   1   because (1 + 1) / 2

def solution(aa, bb):
    alist=[]
    for i in range(len(aa)):
        alist.append((aa[i]-bb[i])*(aa[i]-bb[i]))
    return (sum(alist)/len(aa))

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

String Average  (0) 2022.11.04
Delete a digit  (0) 2022.11.04
What century is it?  (0) 2022.11.04
Arrh, grabscrab!  (0) 2022.11.02
Calculating String Rotation  (0) 2022.11.02