def basis(u, cumul_var, p = 0.5):
    """Return the minimum number of basis vectors 
    from matrix U such that they account for at least p percent
    of total variance.
    
    Hint: Do the singular values really represent the variance?
    
    Args:
        u: (M, M) numpy array containing principal components.
        For example, i'th vector is u[:, i]
        cumul_var: (N, ) numpy array, variance along the principal components.
    
    Returns:
        v: (M, D) numpy array, contains M principal components from N
        containing at most p (percentile) of the variance.
    
    """
    
    #
    # You code here
    #
    d = 0
    var_cm = 0
    # make sure d is at least 1
    p = max(p, 1e-8)
    while var_cm / cumul_var[-1] < p and d < len(cumul_var):
        var_cm = cumul_var[d]
        d += 1
    
    v = u[:, :d]
    return v