true</code></pre><p>The inverse is <code>onecold</code> (which can take a general probability distribution, as well as just booleans).</p><pre><codeclass="language-julia">julia> onecold(ans, [:a, :b, :c])
:c</code></pre><articleclass="docstring"><header><aclass="docstring-binding"id="Flux.onehot"href="#Flux.onehot"><code>Flux.onehot</code></a> — <spanclass="docstring-category">Function</span></header><section><div><pre><codeclass="language-julia">onehot(l, labels[, unk])</code></pre><p>Create a <code>OneHotVector</code> with its <code>l</code>-th element <code>true</code> based on the possible set of <code>labels</code>. If <code>unk</code> is given, return <code>onehot(unk, labels)</code> if the input label <code>l</code> is not found in <code>labels</code>; otherwise it will error.</p><p><strong>Examples</strong></p><pre><codeclass="language-julia-repl">julia> Flux.onehot(:b, [:a, :b, :c])
:c</code></pre></div><aclass="docs-sourcelink"target="_blank"href="https://github.com/FluxML/Flux.jl/blob/c444226db542502a9a0311648de783f87c738a54/src/onehot.jl#L102-L115">source</a></section></article><h2id="Batches-1"><aclass="docs-heading-anchor"href="#Batches-1">Batches</a><aclass="docs-heading-anchor-permalink"href="#Batches-1"title="Permalink"></a></h2><p><code>onehotbatch</code> creates a batch (matrix) of one-hot vectors, and <code>onecold</code> treats matrices as batches.</p><pre><codeclass="language-julia">julia> using Flux: onehotbatch
:b</code></pre><p>Note that these operations returned <code>OneHotVector</code> and <code>OneHotMatrix</code> rather than <code>Array</code>s. <code>OneHotVector</code>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.</p><articleclass="docstring"><header><aclass="docstring-binding"id="Flux.onehotbatch"href="#Flux.onehotbatch"><code>Flux.onehotbatch</code></a> — <spanclass="docstring-category">Function</span></header><section><div><pre><codeclass="language-julia">onehotbatch(ls, labels[, unk...])</code></pre><p>Create a <code>OneHotMatrix</code> with a batch of labels based on the possible set of <code>labels</code>. If <code>unk</code> is given, return <ahref="#Flux.onehot"><code>onehot(unk, labels)</code></a> if one of the input labels <code>ls</code> is not found in <code>labels</code>; otherwise it will error.</p><p><strong>Examples</strong></p><pre><codeclass="language-julia-repl">julia> Flux.onehotbatch([:b, :a, :b], [:a, :b, :c])
0 0 0</code></pre></div><aclass="docs-sourcelink"target="_blank"href="https://github.com/FluxML/Flux.jl/blob/c444226db542502a9a0311648de783f87c738a54/src/onehot.jl#L80-L96">source</a></section></article></article><navclass="docs-footer"><aclass="docs-footer-prevpage"href="../../models/nnlib/">« NNlib</a><aclass="docs-footer-nextpage"href="../dataloader/">DataLoader »</a></nav></div><divclass="modal"id="documenter-settings"><divclass="modal-background"></div><divclass="modal-card"><headerclass="modal-card-head"><pclass="modal-card-title">Settings</p><buttonclass="delete"></button></header><sectionclass="modal-card-body"><p><labelclass="label">Theme</label><divclass="select"><selectid="documenter-themepicker"><optionvalue="documenter-light">documenter-light</option><optionvalue="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <ahref="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> on <spanclass="colophon-date"title="Monday 4 May 2020 13:31">Monday 4 May 2020</span>. Using Julia version 1.3.1.</p></section><footerclass="modal-card-foot"></footer></div></div></div></body></html>