You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/data/onehot.md
+16-16Lines changed: 16 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,15 @@ It's common to encode categorical variables (like `true`, `false` or `cat`, `dog
6
6
julia> using Flux: onehot, onecold
7
7
8
8
julia> onehot(:b, [:a, :b, :c])
9
-
3-element Flux.OneHotVector{3,UInt32}:
10
-
0
9
+
3-element OneHotVector(::UInt32) with eltype Bool:
10
+
⋅
11
11
1
12
-
0
12
+
⋅
13
13
14
14
julia> onehot(:c, [:a, :b, :c])
15
-
3-element Flux.OneHotVector{3,UInt32}:
16
-
0
17
-
0
15
+
3-element OneHotVector(::UInt32) with eltype Bool:
16
+
⋅
17
+
⋅
18
18
1
19
19
```
20
20
@@ -44,16 +44,16 @@ Flux.onecold
44
44
julia> using Flux: onehotbatch
45
45
46
46
julia> onehotbatch([:b, :a, :b], [:a, :b, :c])
47
-
3×3 Flux.OneHotArray{3,2,Vector{UInt32}}:
48
-
0 1 0
49
-
1 0 1
50
-
0 0 0
51
-
52
-
julia> onecold(ans, [:a, :b, :c])
53
-
3-element Vector{Symbol}:
54
-
:b
55
-
:a
56
-
:b
47
+
3×3 OneHotMatrix(::Vector{UInt32}) with eltype Bool:
48
+
⋅ 1 ⋅
49
+
1 ⋅ 1
50
+
⋅ ⋅ ⋅
51
+
52
+
julia> onecold(ans, [:a, :b, :c])
53
+
3-element Vector{Symbol}:
54
+
:b
55
+
:a
56
+
:b
57
57
```
58
58
59
59
Note that these operations returned `OneHotVector` and `OneHotMatrix` rather than `Array`s. `OneHotVector`s behave like normal vectors but avoid any unnecessary cost compared to using an integer index directly. For example, multiplying a matrix with a one-hot vector simply slices out the relevant row of the matrix under the hood.
0 commit comments