1

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?

1 Answer 1

2

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))
Sign up to request clarification or add additional context in comments.

1 Comment

Shows great improvement!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.