Convert list to numpy.ndarray

Tomato·2022년 3월 21일
0

Python

목록 보기
1/5
l_2d = [[0, 1, 2], [3, 4, 5]]

arr_2d = np.array(l_2d)

print(arr_2d)

# [[0 1 2]
#  [3 4 5]]

source: numpy_ndarray_list.py
Multi-dimensional list are just nested lists (list of lists), so it doesn't matter if the number of elements in the list doesn't match.

However, passing it to numpy.array() creates numpy.ndarray whose elements are built-in list.

단순 리스트 하나인 경우 np.ndarray()를 사용하여 리스트를 간단하게 ndarray로 변환할 수 있다. 그러나 싱글 리스트가 아닌 nested 리스트인 경우 np.array()를 사용해야 ndarray로 변환이 가능하다.

profile
Study archive

0개의 댓글

관련 채용 정보