如何展平 Flux.jl 中的数据
How to flatten data in Flux.jl
在Flux.jl中,我在一层中有一些数据要转换为一维数组,以便我可以将其输入到下一层。是否有内置函数可以执行此操作?
Flux 提供了一个内置的 Flux.flatten()
函数,according to the Flux docs:
Reshape arbitrarly-shaped input into a matrix-shaped output, preserving the size of the last dimension.
您可以看到如下示例:
julia> rand(Int8, 3,4,2) # batch of two matrices, each 3 x 4
3×4×2 Array{Int8, 3}:
[:, :, 1] =
-29 -97 61 1
34 -53 4 -16
74 46 41 -40
[:, :, 2] =
10 25 -86 77
94 -48 114 1
-68 -125 35 68
julia> Flux.flatten(ans) # batch of two vectors
12×2 Matrix{Int8}:
-29 10
34 94
74 -68
-97 25
-53 -48
46 -125
61 -86
4 114
41 35
1 77
-16 1
-40 68
在Flux.jl中,我在一层中有一些数据要转换为一维数组,以便我可以将其输入到下一层。是否有内置函数可以执行此操作?
Flux 提供了一个内置的 Flux.flatten()
函数,according to the Flux docs:
Reshape arbitrarly-shaped input into a matrix-shaped output, preserving the size of the last dimension.
您可以看到如下示例:
julia> rand(Int8, 3,4,2) # batch of two matrices, each 3 x 4
3×4×2 Array{Int8, 3}:
[:, :, 1] =
-29 -97 61 1
34 -53 4 -16
74 46 41 -40
[:, :, 2] =
10 25 -86 77
94 -48 114 1
-68 -125 35 68
julia> Flux.flatten(ans) # batch of two vectors
12×2 Matrix{Int8}:
-29 10
34 94
74 -68
-97 25
-53 -48
46 -125
61 -86
4 114
41 35
1 77
-16 1
-40 68