get_wide_all_external_mask#
- caf.toolkit.pandas_utils.get_wide_all_external_mask(df, select)[source]#
Generate an external 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 “external to external”, “external_to_internal”, and “internal to external” area.
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
External zones in travel demand matrices tend to be the last 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_all_external_mask(df,select=[2, 3]) >>> mask array([[False, False, True, True], [False, False, True, True], [ True, True, True, True], [ True, True, True, True]])
Values can be extracted using multiplication
>>> df * mask 0 1 2 3 0 0 0 5 5 1 0 0 5 5 2 5 5 5 5 3 5 5 5 5