将 3D 阵列重塑为 2D
Reshaping 3D array to 2D
查看以下玩具示例:
m = 3;
n = 3;
Y = rand(m,n,2);
例如给我
y(:,:,1) =
0.8314 0.3993 0.6569
0.8034 0.5269 0.6280
0.0605 0.4168 0.2920
y(:,:,2) =
0.4317 0.1672 0.1981
0.0155 0.1062 0.4897
0.9841 0.3724 0.3395
现在当我使用
重塑它时
reshape(Y,m*n,2)
扰乱秩序给我,
0.8314 0.4317
0.8034 0.0155
0.0605 0.9841
0.3993 0.1672
0.5269 0.1062
0.4168 0.3724
0.6569 0.1981
0.6280 0.4897
0.2920 0.3395
because here 2nd row should be
0.3993 0.1672
这可以在重塑之前通过
进行交叉检查
Y(1,1,:)
Y(1,2,:)
etc.
顺序改变。
PS:我有大量数据要输入神经网络,这会影响我的权重相乘的方式。
加入permute
there and then reshape
,像这样-
reshape(permute(y,[2,1,3]),[],size(y,3))
样本运行-
>> y
y(:,:,1) =
0.8314 0.3993 0.6569
0.8034 0.5269 0.628
0.0605 0.4168 0.292
y(:,:,2) =
0.4317 0.1672 0.1981
0.0155 0.1062 0.4897
0.9841 0.3724 0.3395
>> reshape(permute(y,[2,1,3]),[],size(y,3))
ans =
0.8314 0.4317
0.3993 0.1672
0.6569 0.1981
0.8034 0.0155
0.5269 0.1062
0.628 0.4897
0.0605 0.9841
0.4168 0.3724
0.292 0.3395
查看以下玩具示例:
m = 3;
n = 3;
Y = rand(m,n,2);
例如给我
y(:,:,1) =
0.8314 0.3993 0.6569
0.8034 0.5269 0.6280
0.0605 0.4168 0.2920
y(:,:,2) =
0.4317 0.1672 0.1981
0.0155 0.1062 0.4897
0.9841 0.3724 0.3395
现在当我使用
重塑它时reshape(Y,m*n,2)
扰乱秩序给我,
0.8314 0.4317 0.8034 0.0155 0.0605 0.9841 0.3993 0.1672 0.5269 0.1062 0.4168 0.3724 0.6569 0.1981 0.6280 0.4897 0.2920 0.3395
because here 2nd row should be
0.3993 0.1672
这可以在重塑之前通过
进行交叉检查Y(1,1,:)
Y(1,2,:)
etc.
顺序改变。
PS:我有大量数据要输入神经网络,这会影响我的权重相乘的方式。
加入permute
there and then reshape
,像这样-
reshape(permute(y,[2,1,3]),[],size(y,3))
样本运行-
>> y
y(:,:,1) =
0.8314 0.3993 0.6569
0.8034 0.5269 0.628
0.0605 0.4168 0.292
y(:,:,2) =
0.4317 0.1672 0.1981
0.0155 0.1062 0.4897
0.9841 0.3724 0.3395
>> reshape(permute(y,[2,1,3]),[],size(y,3))
ans =
0.8314 0.4317
0.3993 0.1672
0.6569 0.1981
0.8034 0.0155
0.5269 0.1062
0.628 0.4897
0.0605 0.9841
0.4168 0.3724
0.292 0.3395