[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ํ–‰๋ ฌ์˜ ๊ณฑ์…ˆ / ํŒŒ์ด์ฌ / Python
Algorithm/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ํ–‰๋ ฌ์˜ ๊ณฑ์…ˆ / ํŒŒ์ด์ฌ / Python

728x90
๋ฐ˜์‘ํ˜•

 

 

๐Ÿ’กsolutions )

๐Ÿ’ฌ ์˜ˆ๋ฅผ ๋“ค์–ด, AXB ํ–‰๋ ฌ๊ณผ BXC ํ–‰๋ ฌ์˜ ๊ณฑ์…ˆ -> ๋‘ ํ–‰๋ ฌ์—์„œ B์˜ ์ž๋ฆฌ๊ฐ€ ๊ฐ™์€ ์ˆซ์ž์ผ ๋•Œ๋งŒ ๊ณฑ์…ˆ์ด ๊ฐ€๋Šฅํ•˜๋ฉฐ -> ๊ณฑ์…ˆ์˜ ๊ฒฐ๊ณผ๋Š” AXCํ–‰๋ ฌ์ด ๋œ๋‹ค.

๐Ÿ’ฌ ์•„๋ž˜ ์ฝ”๋“œ์—์„œ answer์€ ๊ณฑ์…ˆ์˜ ๊ฒฐ๊ณผ๊ฐ€ ๋˜๋Š” AXCํ–‰๋ ฌ์ด๊ณ ,

๐Ÿ’ฌ i๊ฐ€ A / j๊ฐ€ C / k๊ฐ€ B๋กœ ์‚ผ์ค‘ ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ํ–‰๋ ฌ์˜ ๊ณฑ์…ˆ์„ ๊ตฌํ˜„ํ–ˆ๋‹ค.

 

๐ŸŽซcode )

def solution(arr1, arr2):
    r = len(arr1)
    c = len(arr2[0])
    answer = [[0]*c for _ in range(r)]
    
    for i in range(r):
        for j in range(c):
            for k in range(len(arr1[0])):
                answer[i][j] += arr1[i][k]*arr2[k][j]
    return answer

 

๐Ÿ“Œ description )

๋ฌธ์ œ์ถœ์ฒ˜ : programmers.co.kr/learn/courses/30/lessons/12949?language=python3

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํ–‰๋ ฌ์˜ ๊ณฑ์…ˆ

[[2, 3, 2], [4, 2, 4], [3, 1, 4]] [[5, 4, 3], [2, 4, 1], [3, 1, 1]] [[22, 22, 11], [36, 28, 18], [29, 20, 14]]

programmers.co.kr

๋ฌธ์ œ ์„ค๋ช…

2์ฐจ์› ํ–‰๋ ฌ arr1๊ณผ arr2๋ฅผ ์ž…๋ ฅ๋ฐ›์•„, arr1์— arr2๋ฅผ ๊ณฑํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ ์กฐ๊ฑด

  • ํ–‰๋ ฌ arr1, arr2์˜ ํ–‰๊ณผ ์—ด์˜ ๊ธธ์ด๋Š” 2 ์ด์ƒ 100 ์ดํ•˜์ž…๋‹ˆ๋‹ค.
  • ํ–‰๋ ฌ arr1, arr2์˜ ์›์†Œ๋Š” -10 ์ด์ƒ 20 ์ดํ•˜์ธ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค.
  • ๊ณฑํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฐ์—ด๋งŒ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ

 

 

๋ฐ˜์‘ํ˜•