DrawCategorical operation
Namespace: Microsoft.Quantum.Random
Package: Microsoft.Quantum.QSharp.Foundation
Draws a random sample from a categorical distribution specified by a list of probablities.
operation DrawCategorical (probs : Double[]) : Int
Description
The probability of selecting a specific index is proportional to the value of the array element at that index. Array elements that are equal to zero are ignored and their indices are never returned. If any array element is less than zero, or if no array element is greater than zero, then the operation fails.
Input
probs : Double[]
An array of floating-point numbers proportional to the probability of selecting each index.
Output : Int
An integer $i$ with probability $\Pr(i) = p_i / \sum_i p_i$, where $p_i$
is the $i$th element of probs.
See Also
反馈
提交和查看相关反馈