ectools/fc.py
def RCA(EXM):
    """Calculates RCA (Revealed Comparative Advantage) of export matrix EXM, according to Ballassa.

        Arguments:
            EXM: np.ndarray matrix of floats, of order 2. EXM is intended to be of shape [n_countries,n_products].

        Returns:
            RCA: np.ndarray matrix of floats, of shape [n_countries,n_products], containing the results of the calculation.
    """

    # totals by country, product and world
    totcountry = np.sum(EXM, axis=1)
    totproduct = np.sum(EXM, axis=0)
    totworld = np.sum(totproduct)
    RCA = np.copy(EXM)
    for i in range(len(RCA)):
        RCA[i, :] = RCA[i, :] / totcountry[i]
    # some countries have zero total exports (totcountry here),
    #  so the numerator of the RCA will be nan. let's set it to 0
    RCA[np.isnan(RCA)] = 0
    RCA = np.transpose(RCA)
    for i in range(len(RCA)):
        RCA[i, :] = RCA[i, :] / (totproduct[i] / totworld)
    # some products have zero total exports (totproducts here),
    #  so the denominator of the RCA will be nan.
    # let's set nans to 0
    RCA[np.isnan(RCA)] = 0
    RCA = np.transpose(RCA)
    return RCA
Calculates RCA (Revealed Comparative Advantage) of export matrix EXM, according to Ballassa.

        Arguments:
            EXM: np.ndarray matrix of floats, of order 2. EXM is intended to be of shape [n_countries,n_products].

        Returns:
            RCA: np.ndarray matrix of floats, of shape [n_countries,n_products], containing the results of the calculation.
    
Calculates RCA (Revealed Comparative Advantage) of export matrix EXM, according to Ballassa.
Calculates RCA ( Revealed Comparative Advantage ) of export matrix EXM according to Ballassa .
def RCA(EXM):
    totcountry = np.sum(EXM, axis=1)
    totproduct = np.sum(EXM, axis=0)
    totworld = np.sum(totproduct)
    RCA = np.copy(EXM)
    for i in range(len(RCA)):
        RCA[i, :] = RCA[i, :] / totcountry[i]
    RCA[np.isnan(RCA)] = 0
    RCA = np.transpose(RCA)
    for i in range(len(RCA)):
        RCA[i, :] = RCA[i, :] / (totproduct[i] / totworld)
    RCA[np.isnan(RCA)] = 0
    RCA = np.transpose(RCA)
    return RCA
def RCA ( EXM ) : totcountry = np . sum ( EXM , axis = 1 ) totproduct = np . sum ( EXM , axis = 0 ) totworld = np . sum ( totproduct ) RCA = np . copy ( EXM ) for i in range ( len ( RCA ) ) : RCA [ i , : ] = RCA [ i , : ] / totcountry [ i ] RCA [ np . isnan ( RCA ) ] = 0 RCA = np . transpose ( RCA ) for i in range ( len ( RCA ) ) : RCA [ i , : ] = RCA [ i , : ] / ( totproduct [ i ] / totworld ) RCA [ np . isnan ( RCA ) ] = 0 RCA = np . transpose ( RCA ) return RCA
Calculates RCA (Revealed Comparative Advantage) of export matrix EXM, according to Ballassa.
Calculates RCA ( Revealed Comparative Advantage ) of export matrix EXM according to Ballassa .
"""Calculates RCA (Revealed Comparative Advantage) of export matrix EXM, according to Ballassa.

        Arguments:
            EXM: np.ndarray matrix of floats, of order 2. EXM is intended to be of shape [n_countries,n_products].

        Returns:
            RCA: np.ndarray matrix of floats, of shape [n_countries,n_products], containing the results of the calculation.
    """ # totals by country, product and world # some countries have zero total exports (totcountry here), #  so the numerator of the RCA will be nan. let's set it to 0 # some products have zero total exports (totproducts here), #  so the denominator of the RCA will be nan. # let's set nans to 0
np.ndarray matrix of floats, of shape [n_countries,n_products], containing the results of the calculation.
np . ndarray matrix of floats of shape [ n_countries n_products ] containing the results of the calculation .
RCA
EXM
np.ndarray matrix of floats, of order 2. EXM is intended to be of shape [n_countries,n_products].
np . ndarray matrix of floats of order 2 . EXM is intended to be of shape [ n_countries n_products ] .