Im trying to save a numpy array to a json but since a ndarray is not JSON serializable I am converting them to lists. My problem is that this consumes an excesive amount of RAM. Is there any other lightweight method?
You can use numpyencoder :
import numpy as np
import json
from numpyencoder import NumpyEncoder
numpy_data = np.array([0, 1, 2, 3])
print(json.dumps(numpy_data, cls=NumpyEncoder))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.