arcfish.pl.cast_to_distmat#
- arcfish.pl.cast_to_distmat(X: ~numpy.ndarray, func: ~typing.Callable = <function nanmean>) ndarray#
Cast the input array to a p by p matrix. Specfically,
1. X is a 1d array: treat X as the flattened upper triangle of a (p,p) matrix and refill it into a p*p matrix.
X is a (p,p) symmetric matrix: return X.
3. X is a (p,d) asymmetric matrix, where p might or might not equal to d: treat as the coordinates of a single trace, calculate the pairwise distance matrix.
4. X is a (n,p,p) matrix, where X[i] is symmetric: apply func to each entry (e.g. func = np.nanmean, then this is averaging each entry).
5. X is a (n,p,d) matrix, where p might or might not equal to d: first convert to (n,p,p) by applying 3 to X[i] and then apply 4.
- Parameters:
X (np.ndarray) – Input matrix.
func (Callable, optional) – How to calculate average when the dimension of the input is at least 3, by default np.nanmean.
- Returns:
Output p by p symmetric matrix.
- Return type:
(p,p) np.ndarray