9951 explained code solutions for 126 technologies


python-numpyConvert Numpy array to JSON


import numpy as np
import json as json

a = np.array([[1, 2], [3, 4], [5, 6]])

jsn = json.dumps(a.tolist())ctrl + c
import numpy as np

load Numpy module for Python

import json as json

load JSON module to encode to JSON

np.array

declare Numpy array

[[1, 2], [3, 4], [5, 6]]

sample multi-dimensional array

.tolist()

convert given Numpy array to list

json.dumps

convert given list to JSON