[IT]/python.numpy
numpy.브로드캐스팅
givemebro
2020. 3. 30. 18:11
반응형
a = np.ones([4,3])
a
'''
array([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]])
'''
a+[1,2,3]
'''
[2,3,4]
[2,3,4]
[2,3,4]
[2,3,4]
'''
https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html
Broadcasting — NumPy v1.17 Manual
Broadcasting Note See this article for illustrations of broadcasting concepts. The term broadcasting describes how numpy treats arrays with different shapes during arithmetic operations. Subject to certain constraints, the smaller array is “broadcast” acro
docs.scipy.org
브로드캐스팅 : 아래로, 옆으로 계산을 합리적으로 확장
import numpy as np
a=np.arange(9).reshape(3,-1)
a
'''
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
'''
b=np.arange(1000,4000,1000).reshape(3,1)
b
'''
array([[1000],
[2000],
[3000]])
'''
a+b
'''
array([[1000, 1001, 1002],
[2003, 2004, 2005],
[3006, 3007, 3008]])
'''
c=(np.arange(1,4)*0.1).reshape(3,1)
c
'''
array([[0.1],
[0.2],
[0.3]])
'''
a*c
array([[0. , 0.1, 0.2],
[0.6, 0.8, 1. ],
[1.8, 2.1, 2.4]])반응형