NumPy array is not JSON serializable

when You want to save numpy array obj in json file by python, you can this error what is “NumPy array is not JSON serializable“. This solution is;

first of all, you should convert from numpy array to list and then you should save object.  For instance,

a = numpy.array([1, ,2])
file_path = “/name_file.json”
fp = codecs.open(file_path, ‘w’, encoding=’utf-8′)
json.dump(list(a), fp, separators=(‘,’, ‘:’), sort_keys=True, indent=4)
fp.close()

have a nice day
Resource
[1] https://stackoverflow.com/questions/26646362/numpy-array-is-not-json-serializable

Semiha Makinist Uzman on 1 Haziran 2017 yazdı
Yorum Ekle
  • 0 Yanıt(lar)
  • Yanıtınız

    Cevabınızı göndererek Gizlilik Politikası ve Hizmet Şartlarını kabul ediyorsunuz.