user1518183
user1518183

Reputation: 4771

Python - how to store time series into dataset

I build a parser which converts MIDI song into sequence of note - chord tuples. For each song, it returns list of tuples, where first item is note and second item is set of notes. So resulting data has shape [(note, {chords})], e.g. [(20, {21, 23}), (30, {22, 24, 26, 28})]. Notice that chord could be arbitrary long.

I would like to build a dataset from many songs and later pass them into recurrent neural network. So my question is: What is simplest way to persist this data into file?

I tried h5py library. Unfortunately, it only works with matrices. Though it would be possible to save each pair like that, it would probably be very inefficient, since length of chord is unlimited.

Upvotes: 0

Views: 87

Answers (1)

Demetri Pananos
Demetri Pananos

Reputation: 7404

Pickle it.

#Write
import pickle 
x = [(20, {21, 23}), (30, {22, 24, 26, 28})]

with open('pickle.txt','wb') as f:
    pickle.dump(x,f)

#Read
with open('pickle.txt','rb') as f:
    y = pickle.load(f)

Upvotes: 1

Related Questions