def class_weights(x):
    """ return dictionary of class weights for categorical array"""
    
    n_class = x.max() + 1
    
    csize = []
    for i in range(n_class):
        csize.append((x == i).sum())
    
    w = dict()
    for i in range(n_class):
        w[i] = max(csize)/(csize[i]*n_class)
       
    
    return(w)