a=np.random.dirichlet(np.ones(3),size=1)
I want to use three numbers, where they sum up to 1. However, I noticed that a[0]
will be:
array([0.24414272, 0.01769199, 0.7381653 ])
an index which already contains three elements.
Is there any way to spilt them into three indices?
CodePudding user response:
The default behavior if you don't pass size
is to return a single dimensional array with the specified elements, per the docstring on the function:
size : int or tuple of ints, optional
Output shape. If the give shape is, e.g.,
(m, n)
, thenm * n * k
[wherek
is size of input and sample sequences] samples are drawn. Default isNone
, in which case a vector of lengthk
is returned.
By passing size=1
, you explicitly tell it to make a multidimensional array of size
samples (so, 1
sample, making the outer dimension 1), where not passing size
(or passing size=None
) would still make just one set of samples, as a single 1D array.
Short version: If you just drop the ,size=1
from your call, you'll get what you want.
CodePudding user response:
If that's the only thing you want, then this should work:
a=np.random.dirichlet(np.ones(3),size=1)[0]