iode.Variables.__pow__

Variables.__pow__(other)[source]

Compute the expression \(self^{other}\) ( self ** other ).

Parameters:
other: int, float, numpy ndarray, pandas Series, pandas DataFrame, larray Array or iode Variables

If other is an int or a float, compute ‘value ** other’ for all values of the current (subset of) Variables object. If other is a numpy ndarray, the shape of the ndarray must be compatible with the current (subset of) Variables object. Specifically, the number of rows must be equal to the number of variables and the number of columns must be equal to the number of periods. If other is a pandas Series, it must represent either a single variable or a single period. If other is a pandas DataFrame, it must represent the same variables names and periods as the current (subset of) Variables object. Specifically, the index of the DataFrame must be equal to the variables names and the columns of the DataFrame must be equal to the periods. If other is an larray Array, its last axis must be equal to the periods and be named ‘time’. If the Array has more than two axes, the first n-1 axes are combined to form the variables names. The first (combined) axis must be equal to the variables names. If other is an iode Variables object, it must share the same sample and represent the same set of variables names as self.

Returns:
Variables

Warning

Using a numpy ndarray is not recommended as there is no compatibility check between for the names and periods. The result is not guaranteed to be the one you expected. This possibility is provided for speed reasons (when the database or the subset is large).

Examples

>>> import numpy as np
>>> import pandas as pd
>>> import larray as la
>>> from iode import SAMPLE_DATA_DIR
>>> from iode import variables, NA, Sample
>>> variables.load(f"{SAMPLE_DATA_DIR}/fun.var")
Loading .../fun.var
394 objects loaded
>>> vars_subset = variables["A*", "1991Y1:1995Y1"]
>>> vars_subset.names
['ACAF', 'ACAG', 'AOUC', 'AOUC_', 'AQC']
>>> vars_subset
Workspace: Variables
nb variables: 5
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL

 name       1991Y1  1992Y1  1993Y1  1994Y1  1995Y1
ACAF         26.24   30.16   34.66    8.16  -13.13
ACAG        -30.93  -40.29  -43.16  -16.03  -41.85
AOUC          1.02    1.03    1.03    1.05    1.05
AOUC_         0.96    0.97    0.98    0.99    1.00
AQC           1.06    1.11    1.15    1.16    1.16
>>> # compute 'value ** other' for all values of the current 
>>> # (subset of) Variables object.
>>> new_vars_subset = vars_subset ** 2
>>> new_vars_subset
Workspace: Variables
nb variables: 5
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL

 name       1991Y1   1992Y1   1993Y1  1994Y1   1995Y1
ACAF        688.59       909.57  1201.45   66.60   172.42
ACAG            956.91  1622.96  1862.61  256.93  1751.09
AOUC          1.05         1.06     1.06        1.09     1.10
AOUC_             0.93     0.95     0.96        0.98     0.99
AQC           1.13         1.23     1.33        1.34     1.35
>>> # compute 'V[name, period] ** W[name, period]' for each name and period
>>> # for all names and periods
>>> other = vars_subset.copy()
>>> other = 2.0
>>> new_vars_subset = vars_subset ** other
>>> new_vars_subset
Workspace: Variables
nb variables: 5
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL

 name       1991Y1   1992Y1   1993Y1  1994Y1   1995Y1
ACAF        688.59       909.57  1201.45   66.60   172.42
ACAG            956.91  1622.96  1862.61  256.93  1751.09
AOUC          1.05         1.06     1.06        1.09     1.10
AOUC_             0.93     0.95     0.96        0.98     0.99
AQC           1.13         1.23     1.33        1.34     1.35
>>> # compute 'iode_var[period] ** series[period]' for each period
>>> series = pd.Series([1.0, 2.0, 0.5, 1./4., 2.0], index=vars_subset.periods_as_str)
>>> series
1991Y1    1.00
1992Y1    2.00
1993Y1    0.50
1994Y1    0.25
1995Y1    2.00
dtype: float64
>>> updated_ACAF = vars_subset["ACAF"] ** series
>>> updated_ACAF
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL

 name       1991Y1  1992Y1  1993Y1  1994Y1  1995Y1
ACAF         26.24      909.57    5.89    1.69  172.42
>>> # compute 'single_period_subset[name] ** series[name]' for each name
>>> series = pd.Series([1.0, 2.0, 0.5, 1./4., 2.0], index=vars_subset.names)
>>> series
ACAF     1.00
ACAG     2.00
AOUC     0.50
AOUC_    0.25
AQC      2.00
dtype: float64
>>> vars_subset_1995Y1 = vars_subset[:, "1995Y1"] ** series
>>> vars_subset_1995Y1
Workspace: Variables
nb variables: 5
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1995Y1:1995Y1
mode: LEVEL

 name    1995Y1
ACAF     -13.13
ACAG    1751.09
AOUC       1.02
AOUC_      1.00
AQC        1.35
>>> # compute 'iode_var[name, period] ** df[name, period]' for each name and period
>>> data = np.array([[1.0, 2.0, 0.5, 1./4., 2.0],
...                  [2.0, -1.0, 2.0, -1.0, 2.0], 
...                  [1./4., 2.0, 1.0, 2.0, 0.5],
...                  [0.5, 1./4., 2.0, 1.0, 2.0],
...                  [2.0, 0.5, 1./4., 2.0, 1.0]])
>>> df = pd.DataFrame(data, index=vars_subset.names, columns=vars_subset.periods_as_str) 
>>> df
      1991Y1  1992Y1  1993Y1  1994Y1  1995Y1
ACAF    1.00    2.00    0.50    0.25     2.0
ACAG    2.00   -1.00    2.00   -1.00     2.0
AOUC    0.25    2.00    1.00    2.00     0.5
AOUC_   0.50    0.25    2.00    1.00     2.0
AQC         2.00        0.50    0.25    2.00     1.0
>>> new_vars_subset = vars_subset ** df
>>> new_vars_subset
Workspace: Variables
nb variables: 5
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL

 name       1991Y1  1992Y1   1993Y1  1994Y1   1995Y1
ACAF         26.24      909.57     5.89    1.69   172.42
ACAG            956.91   -0.02  1862.61   -0.06  1751.09
AOUC          1.01        1.06     1.03    1.09     1.02
AOUC_         0.98        0.99     0.96    0.99     0.99
AQC           1.13        1.05     1.04    1.34     1.16
>>> # compute 'iode_var[name, period] ** array[name, period]' for each name and period
>>> axis_names = la.Axis(name="names", labels=vars_subset.names)
>>> axis_time = la.Axis(name="time", labels=vars_subset.periods_as_str)
>>> array = la.Array(data, axes=(axis_names, axis_time))
>>> array
names\time  1991Y1  1992Y1  1993Y1  1994Y1  1995Y1
      ACAF     1.0     2.0     0.5    0.25     2.0
      ACAG     2.0    -1.0     2.0    -1.0     2.0
      AOUC    0.25     2.0     1.0     2.0     0.5
     AOUC_     0.5    0.25     2.0     1.0     2.0
       AQC     2.0     0.5    0.25     2.0     1.0
>>> new_vars_subset = vars_subset ** array
>>> new_vars_subset
Workspace: Variables
nb variables: 5
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL

 name       1991Y1  1992Y1   1993Y1  1994Y1  1995Y1
ACAF         26.24      909.57     5.89   1.69   172.42
ACAG        956.91       -0.02  1862.61  -0.06  1751.09
AOUC          1.01        1.06     1.03   1.09     1.02
AOUC_         0.98        0.99     0.96   0.99     0.99
AQC           1.13        1.05     1.04   1.34     1.16
        
>>> # WARNING: using a numpy ndarray to a (subset of a) Variables object is not recommended 
>>> #          as there is no compatibility check between for the names and periods.
>>> #          The result is not guaranteed to be the one you expected.
>>> #          This possibility is provided for speed reasons 
>>> #          (when dealing with large subsets/databases).
>>> # compute 'iode_var[period] ** data[t]' for each period
>>> data = np.array([1.0, 2.0, 0.5, 1./4., 2.0])
>>> updated_ACAF = vars_subset["ACAF"] ** data
>>> updated_ACAF
Workspace: Variables
nb variables: 1
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL

 name       1991Y1  1992Y1  1993Y1  1994Y1  1995Y1
ACAF         26.24      909.57    5.89    1.69  172.42

>>> # compute 'single_period_subset[name] ** data[i]' for each name
>>> vars_subset_1995Y1 = vars_subset[:, "1995Y1"] ** data
>>> vars_subset_1995Y1
Workspace: Variables
nb variables: 5
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1995Y1:1995Y1
mode: LEVEL

 name       1995Y1
ACAF        -13.13
ACAG       1751.09
AOUC          1.02
AOUC_         1.00
AQC           1.35
        
>>> # compute 'iode_var[name, period] ** data[i, t]' for each name and period
>>> data = np.array([[1.0, 2.0, 0.5, 1./4., 2.0],
...                  [2.0, -1.0, 2.0, -1.0, 2.0], 
...                  [1./4., 2.0, 1.0, 2.0, 0.5],
...                  [0.5, 1./4., 2.0, 1.0, 2.0],
...                  [2.0, 0.5, 1./4., 2.0, 1.0]])
>>> new_vars_subset = vars_subset ** data
>>> new_vars_subset
Workspace: Variables
nb variables: 5
filename: ...fun.var
description: Modèle fun - Simulation 1
sample: 1991Y1:1995Y1
mode: LEVEL

 name       1991Y1  1992Y1   1993Y1  1994Y1   1995Y1
ACAF             26.24  909.57     5.89    1.69   172.42
ACAG            956.91   -0.02  1862.61   -0.06  1751.09
AOUC          1.01        1.06     1.03    1.09     1.02
AOUC_         0.98        0.99     0.96    0.99     0.99
AQC           1.13        1.05     1.04    1.34     1.16