본문 바로가기
반응형
array to json (TypeError: Object of type ndarray is not JSON serializable) class NumpyEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, np.ndarray): return obj.tolist() return json.JSONEncoder.default(self, obj) a = np.array([[1, 2, 3], [4, 5, 6]]) print(a.shape) json_dump = json.dumps({'a': a, 'aa': [2, (2, 3, 4), a], 'bb': [2]}, cls=NumpyEncoder) print(json_dump) 출처 : https://stackoverflow.com/questions/26646362/numpy-array-is-not-json-serializable 2022. 4. 24.
opencv imread error (경로 한글, 영어 섞여있음) import cv2 import numpy as np def isKorean(text): hangul = re.compile('[\u3131-\u3163\uac00-\ud7a3]+') result = hangul.findall(text) if len(result) > 0: return True else: return False if isKorean(file_path) == True: img = cv2.imread(file_path, cv2.IMREAD_COLOR) img = np.fromfile(file_path, np.uint8) img = cv2.imdecode(img, cv2.IMREAD_COLOR) elif isKorean(file_path) == False: img = cv2.imread(fil.. 2022. 4. 14.
opencv error - AttributeError: module 'cv2' has no attribute 'destroyAllwindows' 에러 발생... cv2에 destoryAllwindow()가 없어? # cv2.imshow('img',img) # cv.waitKey(0) # cv.destroyAllwindows("gray") cv2.imshow('img',img) # # Exit if ESC pressed k = cv2.waitKey(0) cv2.destroyAllWindows()​ waitkey(0) 를 변수로 주니깐 성공했어...왜인지 모르겠어...먼 차이지...잘 모르겟당 이미지는 진짜 싫다 2022. 4. 8.
OpenCV error error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' 에러발생 img 읽을 파일이 없음... 이미지 show하기 전 read를 잘했는지 imread()로 잘 읽었는지 확인해보자 2022. 4. 8.
TypeError: __init__() got an unexpected keyword argument 'size' from gensim.models import Word2Vec corpus = [sent.strip().split(" ") for sent in train_txt] model = Word2Vec(corpus, size = 40, workers = 4, sg=1) from gensim.models import Word2Vec corpus = [sent.strip().split(" ") for sent in train_txt] model = Word2Vec(corpus, vector_size = 40, workers = 4, sg=1) 해결 size -> vector_size 2021. 7. 16.
TypeError: expected string or bytes-like object for i in tqdm(range(len(label))): label[i] = re.sub('0',"-1",label[i]) list안의 0을 -1로 바꿔주는 작업중 에러 발생 for i in tqdm(range(len(label))): label[i] = re.sub('0',"-1",str(label[i])) label[i]의 값이 str이 아닌 경우 발생하는 에러로 str(label[i])로 변경하여 에러 해결 2020. 10. 19.
pd.concat() ValueError: Shape of passed values is A와 B라는 Dataframe을 pd.concat()를 사용하여 합치려는데 ValueError: Shape of passed values is (832123, 3), indices imply (554749, 3) 라는 에러 발생.... 합치려는 두 개의 Dataframe의 행 수는 554749로 같은데 왜 832123이라는 에러가 발생했을까... A를 다시 살펴보니 554749 rows x 1 columns 인데 index는 277374밖에 없다..?? A라는 Df 생성시 Dataframe ㄱ, ㄴ 두 개를 합쳐 생성하였는데 A = pd.concat([ㄱ , ㄴ]) 이 때 index에 문제가 생긴것 같았다. A = pd.concat([ㄱ , ㄴ].ignore_index=True) 로 A를 재생성 igno.. 2020. 8. 4.
반응형