반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

numpy.브로드캐스팅 본문

[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]])
반응형

'[IT] > python.numpy' 카테고리의 다른 글

np.moveaxis  (0) 2020.05.13
numpy.score  (0) 2020.05.12
numpy.corrcoef  (0) 2020.04.27
numpy.where.3단 논법  (0) 2020.04.23
numpy.무한대 처리  (0) 2020.03.30
numpy.스칼라 연산  (0) 2020.03.30
numpy.file open  (0) 2020.03.27
numpy.reshape(차원 변경)  (0) 2020.03.26
Comments