본문 바로가기

프로그래밍

numpy array와 python list 차이

  • 덧셈 결과 다름
[1,2,3,4]
[1,2,3,4]

### numpy array
[1,2,3,4] + [1,2,3,4] = [2,4,6,8]

### python list
[1,2,3,4] + [1,2,3,4] = [1,2,3,4,1,2,3,4]
  • python list는 뺄셈, 곱셈, 나눗셈 안됨( 곱셈의 경우 기존 리스트 값이 곱한 값만큼 뒤에 붙여짐)
  • numpy array는 같은 자료형의 데이터만 가능, python list는 다양한 자료형의 데이터 동시에 가능
import numpy as np

list= [1,2,"one","two"]
print(list)
###결과 : [1, 2, 'one', 'two']

nparray = np.array(list)
print(nparray)
###결과 : ['1' '2' 'one' 'two']  ## 왜 되는거지?..



'프로그래밍' 카테고리의 다른 글

python class 정리  (0) 2020.05.25
python 이미지 크롭  (0) 2020.05.19
pandas 까먹는것들  (0) 2020.05.15
python array  (0) 2020.05.13
자주쓰는 python  (0) 2020.05.13