Python Library/NumPy
[NumPy] asarray()
goatlab
2021. 12. 27. 17:25
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