torch_ecg.utils.ensure_lead_fmt

torch_ecg.utils.ensure_lead_fmt(values: ndarray, n_leads: int = 12, fmt: str = 'lead_first') ndarray[source]

Ensure the multi-lead (ECG) signal to be of specified format.

Parameters:
  • values (numpy.ndarray) – Values of the n_leads-lead (ECG) signal.

  • n_leads (int, default 12) – Number of leads of the multi-lead (ECG) signal.

  • fmt (str, default "lead_first") – Format of the output values, can be one of “lead_first” (alias “channel_first”), “lead_last” (alias “channel_last”), case insensitive.

Returns:

ECG signal in the specified format.

Return type:

numpy.ndarray

Examples

>>> values = np.random.randn(5000, 12)
>>> new_values = ensure_lead_fmt(values, fmt="lead_first")
>>> new_values.shape
(5000, 12)
>>> np.allclose(values, new_values.T)
True