<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mds(means, weights, d):
 """ Dimensionality reduction using MDS. Args: means (array):
 genes x clusters weights (array):
 clusters x cells d (int):
 desired dimensionality Returns: W_reduced (array):
 array of shape (d, cells) """

    X = dim_reduce(means, weights, d)
    if X.shape[0]==2:
        return X.dot(weights)
    else:
        return X.T.dot(weights)