manhattan_pairwise_distance¶
- manhattan_pairwise_distance(X: ndarray | List[ndarray], y: ndarray | List[ndarray] | None = None) ndarray [source]¶
Compute the manhattan pairwise distance between a set of time series.
- Parameters:
- Xnp.ndarray or List of np.ndarray
A collection of time series instances of shape
(n_cases, n_timepoints)
or(n_cases, n_channels, n_timepoints)
.- ynp.ndarray or List of np.ndarray or None, default=None
A single series or a collection of time series of shape
(m_timepoints,)
or(m_cases, m_timepoints)
or(m_cases, m_channels, m_timepoints)
. If None, then the manhattan pairwise distance between the instances of X is calculated.
- Returns:
- np.ndarray (n_cases, n_cases)
manhattan pairwise matrix between the instances of X.
- Raises:
- ValueError
If X is not 2D or 3D array when only passing X. If X and y are not 1D, 2D or 3D arrays when passing both X and y.
Examples
>>> import numpy as np >>> from aeon.distances import manhattan_pairwise_distance >>> X = np.array([[[1, 2, 3, 4]],[[4, 5, 6, 3]], [[7, 8, 9, 3]]]) >>> manhattan_pairwise_distance(X) array([[ 0., 10., 19.], [10., 0., 9.], [19., 9., 0.]])
>>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]]) >>> y = np.array([[[11, 12, 13]],[[14, 15, 16]], [[17, 18, 19]]]) >>> manhattan_pairwise_distance(X, y) array([[30., 39., 48.], [21., 30., 39.], [12., 21., 30.]])
>>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]]) >>> y_univariate = np.array([11, 12, 13]) >>> manhattan_pairwise_distance(X, y_univariate) array([[30.], [21.], [12.]])
>>> # Distance between each TS in a collection of unequal-length time series >>> X = [np.array([1, 2, 3]), np.array([4, 5, 6, 7]), np.array([8, 9, 10, 11, 12])] >>> manhattan_pairwise_distance(X) array([[ 0., 9., 21.], [ 9., 0., 16.], [21., 16., 0.]])