matlab中任意度数张量的子张量
Sub-tensor of a tensor with arbitrary degree in matlab
我有一个函数,我输入一个任意度数 d
的张量 T
,大小为 n1 x n2 x ... x nd
。我想输出张量T(1:r,1:r,...,1:r)
。换句话说,一个 r x r x ... x r
个子张量有 d
个 r
个。我在处理可变数字 1:r
时遇到困难。理想情况下,如果可能的话,我想在不重塑 T
的情况下执行此操作。
这对于元胞数组来说非常简单,请考虑以下示例:
% example setup
a = ones(3,3,3,3);
r = 2;
% create indices in cell array
b = cell(1,ndims(a));
b(:) = {1:r};
% evaluate
c = a(b{:});
disp(size(c))
我有一个函数,我输入一个任意度数 d
的张量 T
,大小为 n1 x n2 x ... x nd
。我想输出张量T(1:r,1:r,...,1:r)
。换句话说,一个 r x r x ... x r
个子张量有 d
个 r
个。我在处理可变数字 1:r
时遇到困难。理想情况下,如果可能的话,我想在不重塑 T
的情况下执行此操作。
这对于元胞数组来说非常简单,请考虑以下示例:
% example setup
a = ones(3,3,3,3);
r = 2;
% create indices in cell array
b = cell(1,ndims(a));
b(:) = {1:r};
% evaluate
c = a(b{:});
disp(size(c))