본문 바로가기

프로그래밍 - 활용/에러

[Python] numpy 사용 시에 typeError

📌 오류가 발생한 코드

import numpy as np
A=np.array([[2,3,4],
            [4,8,2],
            [1,2,1]])

print("A: "+A[1,]) #여기서 문제 발생

 

📌 에러명

numpy.core._exceptions.UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U3'), dtype('int32')) -> None

즉, array와 str을 동시에 사용할 수 없다는 것!

 

🔎 최종적인 결정

: 각각 나누어서 작성하였다!

print("A에서 2행 구하기")
print(A[1,])

 

📌 참고 주소

numpy 데이터 타입 모음