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?

asked Jul 3, 2020 at 13:17

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))
answered Jul 3, 2020 at 13:26

1 Comment

Shows great improvement!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.