-
np zeros 타입에러 'cannot interpret '2' as a data type'python source code 2023. 7. 30. 17:36728x90
변수 사용 중 아래와 같은 에러가 발생하여 몇 가지 이유 및 방법 등을 찾아보았다.
np.zeros typeerror: cannot interpret '2' as a data type
The signature of the numpy.zeros method is the following.
numpy.zeros(shape, dtype=float, order='C', *, like=None)
The first argument (shape) can be an integer or a tuple of integers.
위의 내용과 같이 shape에 대해 int 또는 튜플 형태의 정의를 해주어야 한다.
import numpy as np arr = np.zeros((2, 3)) # 👇️ [[0. 0. 0.] # [0. 0. 0.]] print(arr)
* 참고로 리스트 형식도 반영이 가능하다.
.https://bobbyhadz.com/blog/python-typeerror-cannot-interpret-4-as-a-data-type
TypeError: Cannot interpret '4' as a data type error [Solved] | bobbyhadz
The TypeError: Cannot interpret '4' as a data type occurs when we pass an integer as the second argument to the `numpy.zeros()` method.
bobbyhadz.com
반응형'python source code' 카테고리의 다른 글
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was inhomogeneous part. 에러 파이썬 문제 해결 (0) 2023.08.04 python numpy multi dimension random choice 에러 해결 (0) 2023.08.04 openAI gym 환경 생성 알아보기 (2) (0) 2023.07.22 openAI gym 환경 생성 알아보기 (1) (0) 2023.07.22 python 멀티프로세싱 pool process 에 대한 정리 (2) 2023.06.20