The following variables seem to be similar but they aren't and I don't understand why:
import ujson
import numpy as np
arr = np.array([1, 2, 3, 4])
arr_1 = arr.tolist()
arr_2 = list(arr)
arr_1 == arr_2 # True
ujson.dumps({'arr': arr_1}) # it works
ujson.dumps({'arr': arr_2}) # it does not work (OverflowError: Maximum recursion level reached)
I am using Python-3.5.6, ujson-1.35 and numpy-1.16.4.
Thank you a lot for your help!!
tolistconverts it all the way.list()just iterates on the first dimension. In this casearr_2is a list ofnp.intobjects, where asarr_1is a list of python integers.ujsonhas a recursion error. Perhaps it tries to represent theint32number as a dictionary-like object and fails. If you use the standardjsonlibrary you will see that the problem is that it does not know how to serialize numbers stored in thenumpyint32type. See this question