def save_svmlight_data(data, labels, data_filename, data_folder=''):
    file = open(data_folder + data_filename, 'w')
for i, x in enumerate(data):
    indexes = x.nonzero()[0]
values = x[indexes]
label = '%i' % labels[i]
pairs = [('%i:%f' % (indexes[i] + 1, values[i])) for i in range(len(indexes))]
sep_line = [label]
sep_line.extend(pairs)
sep_line.append('\n')
line = ' '.join(sep_line)
file.write(line)
python program to export numpy/lists in svmlight format