mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-27 00:37:19 +00:00
Refactor json_encode_np
This commit is contained in:
18
gym/utils/json_utils.py
Normal file
18
gym/utils/json_utils.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import numpy as np
|
||||
|
||||
def json_encode_np(obj):
|
||||
"""
|
||||
JSON can't serialize numpy types, so convert to pure python
|
||||
"""
|
||||
if isinstance(obj, np.ndarray):
|
||||
return list(obj)
|
||||
elif isinstance(obj, np.float32):
|
||||
return float(obj)
|
||||
elif isinstance(obj, np.float64):
|
||||
return float(obj)
|
||||
elif isinstance(obj, np.int32):
|
||||
return int(obj)
|
||||
elif isinstance(obj, np.int64):
|
||||
return int(obj)
|
||||
else:
|
||||
return obj
|
Reference in New Issue
Block a user