728x90
반응형
SMALL
asarray()
리스트 및 튜플을 Numpy 배열로 변환하는 방법
import numpy as np
# from list to numpy array
list_sample = [1, 2, 3, 4, 5]
print(list_sample) # [1, 2, 3, 4, 5]
numpy_sample = np.asarray(list_sample)
print(numpy_sample) # [1 2 3 4 5]
# from tuple to numpy array
list_sample = (1, 2, 3, 4, 5)
print(list_sample) # (1, 2, 3, 4, 5)
numpy_sample = np.asarray(list_sample)
print(numpy_sample) # [1 2 3 4 5]
import numpy as np
# from list to numpy array
list_sample = [(1, 2, 3), [4, 5], [(6, 7), (8, 9)]]
print(list_sample) # [(1, 2, 3), [4, 5], [(6, 7), (8, 9)]]
numpy_sample = np.asarray(list_sample)
print(numpy_sample) # [(1, 2, 3), list[4, 5], list[(6, 7), (8, 9)]]
* 다양한 차원은 변환되지 않는다.
728x90
반응형
LIST
'Python Library > NumPy' 카테고리의 다른 글
[NumPy] numpy array 전체 출력 (0) | 2021.12.31 |
---|---|
[NumPy] numpy 원소 재배열 (0) | 2021.12.30 |
[NumPy] numpy 원소 제거 및 추가 (0) | 2021.12.29 |
[NumPy] numpy.ndarray (0) | 2021.12.27 |
넘파이 (NumPy) (0) | 2021.12.27 |