pymrio.build_agg_matrix
- pymrio.build_agg_matrix(agg_vector, pos_dict=None)
Aggregation based on mapping given in input as numerical or str vector.
- Parameters
agg_vector (list or vector like numpy ndarray) – This can be row or column vector. Length m with position given for n and -1 if values should not be included or length m with id_string for the aggregation
pos_dict (dictionary) – (only possible if agg_vector is given as string) output order for the new matrix must be given as dict with ‘string in agg_vector’ = pos (as int, -1 if value should not be included in the aggregation)
- Returns
agg_matrix – Aggregation matrix with shape (n, m) with n (rows) indicating the new classification and m (columns) the old classification
- Return type
numpy ndarray
Examples
Assume an input vector with either
>>> inp1 = np.array([0, 1, 1, 2])
or
>>> inp2 = ['a', 'b', 'b', 'c']
inp1 and inp2 are equivalent, the entries are just indicators.
>>> build_agg_matrix(inp1) >>> build_agg_matrix(inp2)
Returns
>>> array([[1., 0., 0., 0.], >>> [0., 1., 1., 0.], >>> [0., 0., 0., 1.]])
The order can be defined by a dictionary, thus
>>> pymrio.build_agg_matrix(np.array([1, 0, 0, 2]))
is equivalent to
>>> pymrio.build_agg_matrix(['b', 'a', 'a', 'c'], dict(a=0,b=1,c=2))
>>> array([[0., 1., 1., 0.], >>> [1., 0., 0., 0.], >>> [0., 0., 0., 1.]])