Numpy. section5 : ndarray의 원소별 연산과 브로드캐스팅. Lec20. ndim이 2일 때의 브로드캐스팅

timekeeep·2023년 2월 25일
0

Numpy

목록 보기
19/28

[1] ndim이 2일 때의 브로드캐스팅

  • 1이 맞춰지면서 브로드캐스팅이 일어난다

  • (2,3,3) + (1,3,3)

  • (2,3,3) + (2,1,3)

  • (2,3,3) + (2,3,1)

#(2,3,3) + (1,3,3)

import numpy as np

A = np.arange(18).reshape((2,3,3))
B = 10*np.arange(9).reshape((1,3,3))
C = A + B

print("A: {}/{}\n{}".format(A.ndim, A.shape, A))
print("B: {}/{}\n{}\n".format(A.ndim, B.shape, B))

print("A + B: {}/{}\n{}".format(A.ndim, C.shape, C))

#(2,3,3) + (2,1,3)

import numpy as np

A = np.arange(18).reshape((2,3,3))
B = 10*np.arange(9).reshape((2,1,3))
C = A + B

print("A: {}/{}\n{}".format(A.ndim, A.shape, A))
print("B: {}/{}\n{}\n".format(A.ndim, B.shape, B))

print("A + B: {}/{}\n{}".format(A.ndim, C.shape, C))

#(2,3,3) + (2,3,1)

import numpy as np

A = np.arange(18).reshape((2,3,3))
B = 10*np.arange(9).reshape((2,3,1))
C = A + B

print("A: {}/{}\n{}".format(A.ndim, A.shape, A))
print("B: {}/{}\n{}\n".format(A.ndim, B.shape, B))

print("A + B: {}/{}\n{}".format(A.ndim, C.shape, C))
profile
Those who are wise will shine like the brightness of the heavens, and those who lead many to righteousness, like the stars for ever and ever

0개의 댓글