def pca_calc(nc, d):
    """
    Calculates pca of d.
    
    Parameters
    ----------
    nc : int
        Number of components
    d : np.ndarray
        An NxM array, containing M observations of N variables.
        Data must be floats. Can contain NaN values.
    
    Returns
    -------
    pca, dt : tuple
        fitted PCA object, and transformed d (same size as d).
    """
    
    # check for and remove nans
    ind = ~np.apply_along_axis(any, 1, np.isnan(d))

    if any(~ind):
        pcs = np.full((d.shape[0], nc), np.nan)
        d = d[ind, :]

    pca = PCA(nc).fit(d)
    
    if any(~ind):
        pcs[ind, :] = pca.transform(d)
    else:
        pcs = pca.transform(d)
    
    return pca, pcs
def pca_calc(nc, d):
    """
    Calculates pca of d.
    
    Parameters
    ----------
    nc : int
        Number of components
    d : np.ndarray
        An NxM array, containing M observations of N variables.
        Data must be floats. Can contain NaN values.
    
    Returns
    -------
    pca, dt : tuple
        fitted PCA object, and transformed d (same size as d).
    """
    
    # check for and remove nans
    ind = ~np.apply_along_axis(any, 1, np.isnan(d))

    if any(~ind):
        pcs = np.full((d.shape[0], nc), np.nan)
        d = d[ind, :]

    pca = PCA(nc).fit(d)
    
    if any(~ind):
        pcs[ind, :] = pca.transform(d)
    else:
        pcs = pca.transform(d)
    
    return pca, pcs
def pca_calc ( nc , d ) : # check for and remove nans ind = ~ np . apply_along_axis ( any , 1 , np . isnan ( d ) ) if any ( ~ ind ) : pcs = np . full ( ( d . shape [ 0 ] , nc ) , np . nan ) d = d [ ind , : ] pca = PCA ( nc ) . fit ( d ) if any ( ~ ind ) : pcs [ ind , : ] = pca . transform ( d ) else : pcs = pca . transform ( d ) return pca , pcs
Calculates pca of d.
    
    Parameters
    ----------
    nc : int
        Number of components
    d : np.ndarray
        An NxM array, containing M observations of N variables.
        Data must be floats. Can contain NaN values.
    
    Returns
    -------
    pca, dt : tuple
        fitted PCA object, and transformed d (same size as d).
Calculates pca of d . Parameters ---------- nc : int Number of components d : np . ndarray An NxM array containing M observations of N variables . Data must be floats . Can contain NaN values . Returns ------- pca dt : tuple fitted PCA object and transformed d ( same size as d ) .