class NpEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
if isinstance(obj, np.floating):
return float(obj)
if isinstance(obj, np.ndarray):
return obj.tolist()
return super(NpEncoder, self).default(obj)
위 클래스 선언해주고 아래처럼 cls로 넣어줌
json_path = os.path.join(args.project_dir, '4step.json')
with open(json_path, 'w') as outfile:
json.dump(cluster, outfile, cls=NpEncoder)