Skip to content

Instantly share code, notes, and snippets.

@seanie12
Created February 8, 2020 06:24
Show Gist options
  • Save seanie12/15884777dcf04cede9e1469adf2666a1 to your computer and use it in GitHub Desktop.
Save seanie12/15884777dcf04cede9e1469adf2666a1 to your computer and use it in GitHub Desktop.
import os
import random
from tqdm import tqdm
import numpy as np
def batch_loader(iterable, batch_size, shuffle=False):
length = len(iterable)
if shuffle:
random.shuffle(iterable)
for start_idx in range(0, length, batch_size):
yield iterable[start_idx: min(length, start_idx + batch_size)]
dataset_list = []
num_files = 4
dir_name = "./data"
fw = open("./data/eeg.txt", "w")
for i in tqdm(range(1, num_files + 1)):
file_x_name = os.path.join(dir_name, "st_triple_{}_x.npy".format(i))
file_y_name = os.path.join(dir_name, "st_triple_{}_y.npy".format(i))
xs = np.load(file_x_name)
ys = np.load(file_y_name)
for x, y in zip(xs, ys):
flatten_x = np.reshape(x, -1).tolist()
str_list = [str(x) for x in flatten_x]
str_x = " ".join(str_list)
str_y = str(y)
fw.write("{}\t{}\n".format(str_x, y))
fw.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment