tensorly.base.partial_unfold

partial_unfold(tensor, mode=0, skip_begin=1, skip_end=0, ravel_tensors=False)[source]

Partially unfolds a tensor while ignoring the specified number of dimensions at the beginning and the end.

For instance, if the first dimension of the tensor is the number of samples, to unfold each sample, you would set skip_begin=1. This would, for each i in range(tensor.shape[0]), unfold tensor[i, ...].
Parameters:

tensor : ndarray

tensor of shape n_samples x n_1 x n_2 x … x n_i

mode : int

indexing starts at 0, therefore mode is in range(0, tensor.ndim)

skip_begin : int, optional

number of dimensions to leave untouched at the beginning

skip_end : int, optional

number of dimensions to leave untouched at the end

ravel_tensors : bool, optional

if True, the unfolded tensors are also flattened

Returns:

ndarray

partially unfolded tensor