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, set skip_begin=1. This would, for each i in range(tensor.shape[0]), unfold tensor[i, ...].

Parameters:
tensorndarray

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

modeint

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

skip_beginint, optional

number of dimensions to leave untouched at the beginning

skip_endint, optional

number of dimensions to leave untouched at the end

ravel_tensorsbool, optional

if True, the unfolded tensors are also flattened

Returns:
ndarray

partially unfolded tensor