본문 바로가기
데이터 분석

Numpy Broadcasting

by ma_ro 2020. 2. 29.

### 브로드캐스팅 ( Broadcasting )

- shape이 같은 두 ndarray에 대한 연산은 각 원소 별로 진행
- 연산되는 두 ndarray가 다른 shape을 같는 경우,  브로드캐스팅 후 진행
- shape 맞추기라고 할 수 있음

https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html#general-broadcasting-rules



### 브로드캐스팅 Rule

- 뒷 차원에서부터 비교하여 shape이 같거나, 차원 중 값이 1인 것이 존재하면 가능



```python
a = np.arange(12).reshape(4, 3)
b = np.arange(100, 103)

a + b
array([[100, 102, 104],
       [103, 105, 107],
       [106, 108, 110],
       [109, 111, 113]])
```

'데이터 분석' 카테고리의 다른 글

Pandas DataFrame - CRUD  (0) 2020.03.01
Pandas Series  (0) 2020.03.01
Numpy 기본 함수  (0) 2020.02.29
Numpy ndarray shape 변경  (0) 2020.02.29
Numpy ndarray 인덱싱, 슬라이싱  (0) 2020.02.29

댓글