I fetch a big array of data from a server. I store it in a combination of a dictionary and multi-dimensional array, and it will be used for a simple plot. It looks like:
>> print(data)
{'intensity_b2': [array([ 1.46562588e+09, 1.46562588e+09, 1.46562588e+09, ...,
1.46566369e+09, 1.46566369e+09, 1.46566369e+09]), array([ 0., 0., 0., ..., 0., 0., 0.])]}
>> print(len(data['intensity_b2'][0]))
37071
To avoid fetching the data every time I run the script I want to save this data structure to a file. I try to store the data as
with open("data.dat", 'w') as f:
f.write(str(data))
and read it with
with open(data_store, 'r') as f:
data = ast.literal_eval(f.read())
as suggested here. However, I get an error
ValueError: malformed node or string: <_ast.Call object at 0x108fce5f8>
which I suspect is due to the fact that the data gets stored with the ...
as was shown in the first printout (i.e. the first print(data)
above is literally how the data looks in the file). How do I write a dictionary with a big array to a file and read it subsequently?