728x90 반응형 Python/Error14 [Python_Error] ValueError: can only convert an array of size 1 to a Python scalar 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 하는지 작성했다. ValueError: can only convert an array of size 1 to a Python scalar 위 에러는 numpy 내에 하나의 스칼라 값이 아니라 여러 개의 값을 갖고 있을 때 안에 인자를 가져오려고 .item()을 사용하다가 발생한 오류이다. numpy.ndarray.item 넘파이 배열 내에 요소들을 반환하는 함수이다. 위 설명에 적혀있듯이 스칼라 값을 복사하여 반환한다고 적혀있다. 따라서 배열 형태의 넘파이 뒤에는 item()이 들어올 수 없다. 다음과 같이 안에 있는 요소들을 뽑아서 분석 혹은 처리를 해주고 싶을 때는, 다음과 같이 리스트안에서 하나씩 불러다가 처리하는 것이 마음 편하다. 2023. 1. 30. [Python_Error] ValueError: zero-size array to reduction operation maximum which has no identity 본 포스팅에서는 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 하는지 작성하고자 한다. ValueError: zero-size array to reduction operation maximum which has no identity 해당 오류는 비어있는 array를 np.max 혹은 np.min을 사용하여 발생했던 오류이다. [예시] 오류가 발생한 코드와 유사하게 예시를 만들어보았다. import numpy as np mask = np.array([[1,2],[3,4]]) zz = np.where(mask == 5)[0] print((zz.max() + zz.min()) / 2.) """ ValueError Traceback (most recent call last) /aidata/lung/WOR.. 2023. 1. 25. [Python_Error] ValueError: The dimension of bins must be equal to the dimension of the sample x. 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 하는지 작성했다. ValueError: The dimension of bins must be equal to the dimension of the sample x. 위 에러메시지는 "np.histogram2d()" 모듈을 사용할 때 발생한 오류이다. import numpy as np # Generate some random data data_1 = np.random.randn(100, 2) # Generate some random data data_2 = np.random.randn(150, 2) # Try to create a 2D histogram with one-dimensional bins hist, _, _ = np.histogr.. 2023. 1. 9. [Python_Error] ModuleNotFoundError: No module named 'IPython.html' 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 하는지 작성했다. ModuleNotFoundError: No module named 'IPython.html' 말 그대로 IPython.html 모듈이 없다는 오류이다. 보통 예전에 만들어진 코드를 가져다 쓸 때 보통 발생했던 오류이다. 필자는 IPython.html에 있는 widgets 함수를 가져다 쓰려다 오류가 발생했다. 오류 수정은 간단하다. widget을 사용하기 위해 IPython이 아니라 ipywidget을 사용하면 문제가 해결된다. ipywidget에는 interact, button과 같은 UI에 도움이 되는 함수들이 많이 내장되어 있다. from ipywidgets import interact, Button import I.. 2023. 1. 9. 이전 1 2 3 4 다음 728x90 반응형