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
Memory efficient one-hot array encodings (primarily for use in machine-learning contexts like Flux.jl).
6
+
7
+
## Usage
8
+
9
+
One-hot arrays are boolean arrays where only a single element in the first dimension is `true` (i.e. "hot"). OneHotArrays.jl stores such arrays efficiently by encoding a N-dimensional array of booleans as a (N - 1)-dimensional array of integers. For example, the one-hot vector below only uses a single `UInt32` for storage.
10
+
11
+
```julia
12
+
julia> β =onehot(:b, (:a, :b, :c))
13
+
3-element OneHotVector(::UInt32) with eltype Bool:
14
+
⋅
15
+
1
16
+
⋅
17
+
```
18
+
19
+
As seen above, the one-hot encoding can be useful for representing labeled data. The label `:b` is encoded into a 3-element vector where the "hot" element indicates the label from the set `(:a, :b, :c)`.
20
+
21
+
We can also encode a batch of one-hot vectors or reverse the encoding.
In addition to functions for encoding and decoding data as one-hot, this package provides numerous "fast-paths" for linear algebraic operations with one-hot arrays. For example, multiplying by a matrix by a one-hot vector triggers an indexing operation instead of a matrix multiplication.
0 commit comments