<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def cov2corr(cov):
 """Calculate the correlation matrix based on a covariance matrix Parameters cov: 2D array Returns ------- corr: 2D array correlation converted from the covarince matrix """

    assert cov.ndim == 2, 'covariance matrix should be 2D array'
    inv_sd = 1 / np.sqrt(np.diag(cov))
    corr = cov * inv_sd[None, :] * inv_sd[:, None]
    return corr