get_wide_internal_only_mask#
- caf.toolkit.pandas_utils.get_wide_internal_only_mask(df, select)[source]#
Generate an internal only mask for a wide matrix.
This is a common operation in wide travel demand matrices. When a matrix contains both “internal” and “external” demand, this function can be used to generate a mask that selects the “internal to internal” area only.
To extract values from the given df perform df * mask.
- Parameters:
- Returns:
A mask of True and False values. Will be the same shape as df.
- Return type:
mask
See also
Examples
Internal zones in travel demand matrices tend to be the first in the matrix
>>> df = pd.DataFrame(np.full((4, 4), 5)) >>> df 0 1 2 3 0 5 5 5 5 1 5 5 5 5 2 5 5 5 5 3 5 5 5 5
>>> mask = get_wide_internal_only_mask(df,select=[0, 1]) >>> mask array([[ True, True, False, False], [ True, True, False, False], [False, False, False, False], [False, False, False, False]])
Values can be extracted using multiplication
>>> df * mask 0 1 2 3 0 5 5 0 0 1 5 5 0 0 2 0 0 0 0 3 0 0 0 0