to solve the error you are asking for you can try this but it'll still have other errors after that import nimpy let rnd = pyImport("random") proc cross_validation_split(dataset:seq[float], n_folds:int): seq[float]= var dataset_split : seq[float] var dataset_copy = dataset var fold_size = int(dataset.len/n_folds) for i in 0..n_folds: var fold : seq[float] while fold.len < fold_size: var index = rnd.randrange(dataset_copy.len) fold.append(dataset_copy.pop(index)) dataset_split.append(fold) return dataset_split Run
doing this however should get you the result you are looking for import random proc cross_validation_split(dataset:seq[float], n_folds:int): seq[float]= var dataset_split : seq[float] var dataset_copy = dataset var fold_size = int(dataset.len/n_folds) for i in 0..n_folds: var fold : seq[float] while fold.len < fold_size: var index = rand(dataset_copy.len) fold.add dataset_copy[index] dataset_copy.delete(index) dataset_split.add(fold) return dataset_split Run