일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- GT-S80
- DFS
- E-P1
- Button
- SciPy
- Lotto
- RNN
- mariadb
- install
- CNN
- mean
- dataframe
- pycharm
- LSTM
- Splunk
- Series
- ipad
- SPL
- imread
- Python
- 알고리즘
- keras
- 삼성소프트웨어멤버십
- synology
- pandas
- pip
- GitHub
- Numpy
- javascript
- index
Archives
- Today
- Total
잠토의 잠망경
[numpy] np.isin(), np.where() index 찾아보기 본문
np.isin()
내가 찾는게 있는지 여부를 각 index 위치에 True, False 형태로 알려줌
1,4,6,10이 포함되어 있는지를 찾고 싶을때 사용한다.
from numpy import ndarray
import numpy as np
datas = np.asarray([1,2,3,4,5,6,7])
# 이 값들의 포함 여부를 알려달라.
iwantit = np.asarray([1,4,6,10])
# 해당 ndarray의 index 위치에 포함 여부가 표시된다.
print(np.isin(datas, iwantit))
#[ True False False True False True False]
np.where()
내가 원하는 조건이 맞으면 index 위치를 알려준다.
포함 여부를 index로 치환해보자.
# 해당 ndarray의 index를 표기한다.
# (array([0, 3, 5], dtype=int64),)
print(np.where(np.isin(datas, iwantit) == True))
# 0번째에 우리가 원하는 index list가 있다.
# 그래서 [0]를 사용한다.
indexlist = np.where(np.isin(datas, iwantit) == True)[0]
for item in indexlist:
print(item)
Comments