Help on return type(?)

Robert rxjwg98 at gmail.com
Sat Jan 9 20:45:59 EST 2016


Hi,

I see below code snippet. The return line is not as the usual type.



def make_cov(cov_type, n_comp, n_fea):
    mincv = 0.1
    rand = np.random.random
    return {
        'spherical': (mincv + mincv * np.dot(rand((n_components, 1)),
                                             np.ones((1, n_features)))) ** 2,
        'tied': (make_spd_matrix(n_features)
                 + mincv * np.eye(n_features)),
        'diag': (mincv + mincv * rand((n_components, n_features))) ** 2,
        'full': np.array([(make_spd_matrix(n_features)
                           + mincv * np.eye(n_features))
                          for x in range(n_components)])
    }[cov_type]

Specifically, could you explain the meaning of 

{
...    }[cov_type]

to me?


Thanks,



More information about the Python-list mailing list