lundi 6 septembre 2021

Shuffling returns data None

I know this is pretty basic but I when calling my function for shuffling data it returns None. I tried multiple versions of placing the return statement but nothing seems to work.

def _shuffle_variables(var, aux_var, label, technique):
    #from collections.abc import Iterable
    import random
    
    arg_data = inspect.getfullargspec(_shuffle_variables)[0]
    sorted_var = []
    dict_var = {} 
    if technique == 'acoustic':
        #nested_arg = check_nested_input_arg(var, aux_var, label)
        #args = [var, aux_var,label]
        is_nested_args = [True, False, False]

        #shuffle indices with length of label
        if is_nested_args[2] == False:
            idx_shuffled = list(range(0, len(label)))
            random.shuffle(idx_shuffled)
        else:
            idx_shuffled = list(range(0, np.array(label).shape[1]))
            random.shuffle(idx_shuffled)
        
        for i in range(len(arg_data)):
            if is_nested_args == True:
                for k in range(np.array(eval(arg_data[i])).shape):
                    sort_var = [np.array(eval(arg_data[i]))[k][j] for j in idx_shuffled]
                    sorted_var.append(sort_var)
                    #print(sort_var)
                    dict_var[str(k)] = sort_var
                return sorted_var
            elif is_nested_args == False:
                sort_var = [np.array(eval(arg_data[i]))[j] for j in idx_shuffled]
                dict_var[arg_data[i]] = sort_var
                sorted_var.append(sort_var)
                return sorted_var
    return sorted_var #dict_var
  

nested_list1 = [[random.random() for x in range(6249)] for x in range(6357)]
nested_list2 = [[random.random() for x in range(6249)] for x in range(6357)]
var = [random.random() for x in range(6249)]
label = [random.random() for x in range(6249)]

idx = _shuffle_variables([nested_list1, nested_list2], var, label, 'acoustic')



Aucun commentaire:

Enregistrer un commentaire