import random


def setup_matrix(pre_dim, post_dim, static_w, sparsity):
    """Create a weight matrix to use in syn dict."""
    weights = []
    valid_values = int(post_dim * sparsity)
    for i in range(0, pre_dim):
        arow = (
            ([float(static_w), ] * valid_values) +
            ([0., ] * int(post_dim - valid_values))
        )
        random.shuffle(arow)
        weights.append(arow)
    return weights