tkinter 그림그리기
# 마우스 그림 def draw(event): global x0, y0 canvas.create_line(x0, y0, event.x, event.y) x0,y0 = event.x, event.y def down(event): global x0, y0 x0, y0 = event.x, event.y def up(event): global x0, y0 if (x0,y0)== (event.x, event.y): canvas.create_line(x0,y0, x0+1, y0+1) from tkinter import * import tkinter tk = tkinter window = tk.Tk() canvas = Canvas(window, width=300, height=300) canvas.bind("",dr..
2022. 8. 1.
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.