torch_openreml.utils.numeric_to_design_matrix¶
- torch_openreml.utils.numeric_to_design_matrix(*args, dtype=None, device=None)[source]¶
Construct a design matrix from one or more numeric vectors or tensors.
Each argument becomes one column of the resulting design matrix. All inputs must have the same length along the first dimension.
- Parameters:
*args (torch.Tensor, list, or tuple) – One or more numeric vectors of equal length. Lists and tuples are converted to tensors.
dtype (torch.dtype, optional) – Desired dtype of the matrix. Defaults to the PyTorch default dtype.
device (torch.device, optional) – Desired device of the matrix. Defaults to the PyTorch default device.
- Returns:
Design matrix of shape
(n, num_args).- Return type:
torch.Tensor
- Raises:
ValueError – If no inputs are provided, or if inputs have inconsistent lengths.
TypeError – If any input is not a tensor, list, or tuple.
Example:
import torch from torch_openreml.utils import numeric_to_design_matrix x1 = torch.tensor([1.0, 2.0, 3.0]) x2 = torch.tensor([4.0, 5.0, 6.0]) numeric_to_design_matrix(x1, x2)
tensor([[1., 4.], [2., 5.], [3., 6.]])