将JSON文件转换为numpy数组

时间:2018-07-25 12:49:24

标签: python json numpy

此.json文件包含来自ECG机器的记录。 文件格式如下:

[-0.140625,-0.15234375,-0.15234375,...,-0.19335937499999997,0 ]

但是,当我尝试使用此代码时,它显示了一个错误

def load_tester(path):
  dataset = '{"fruits": }'
  data = json.loads(path)
  print(data)
  return(np.asarray(nt))

这是错误:

raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

我想将该文件保存到numpy数组中,并变得与json使用的格式相同。

1 个答案:

答案 0 :(得分:6)

您正在尝试使用文件名而不是文件中的数据加载json usign

{ "index":{"_index":"schools", "_type":"school", "_id":"1" }}
{ "name":"Central School", "description":"CBSE Affiliation", "street":"Nagan",  "city":"paprola", "state":"HP", "zip":"176115", "location":[31.8955385, 76.8380405],  "fees":2000, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5\n"}
{ "index":{ "_index":"schools", "_type":"school", "_id":"2"  }}
{ "name":"Saint Paul School", "description":"ICSE Afiliation", "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075","location":[28.5733056, 77.0122136], "fees":5000,"tags":["Good Faculty", "Great Sports"], "rating":"4.5\n" }
{ "index":{"_index":"schools", "_type":"school", "_id":"3"}}
{ "name":"Crescent School", "description":"State Board Affiliation", "street":"Tonk Road", "city":"Jaipur", "state":"RJ", "zip":"176114","location":[26.8535922, 75.7923988],"fees":2500, "tags":["Well equipped labs"], "rating":"4.5\n"}