Skip to content

BUG: numpy.random.Generator.dirichlet should accept zeros. #22547

@WayneHajas

Description

@WayneHajas

Describe the issue:

numpy.random.mtrand.RandomState.dirichlet no longer accepts alpha(count)-values that are zero.

With older (e.g. 1.11.3) versions of numpy, dirichlet accepted zero as an alpha(count) value.

numpy.version
'1.11.3'
dirichlet([5,9,0,8])
array([ 0.17970351, 0.35902845, 0. , 0.46126803])
dirichlet([5,9,0,8])
array([ 0.15228294, 0.45822224, 0. , 0.38949482])

With newer (e.g. 1.21.5) versions of numpy, alpha(count) values must be greater than zero. Very small real-values are accepted.

numpy.version
'1.21.5'
dirichlet([5,9,0.000001,8])
array([0.38285451, 0.26206592, 0. , 0.35507958])
dirichlet([5,9,0,8])
Traceback (most recent call last):
File "", line 1, in
File "mtrand.pyx", line 4390, in numpy.random.mtrand.RandomState.dirichlet
ValueError: alpha <= 0

I have some applications where alpha(count|)-values are raw-data and zero is a very valid value. These applications worked with old versions of numpy but not with newer versions.

Reproduce the code example:

dirichlet([5,9,0,8])

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mtrand.pyx", line 4390, in numpy.random.mtrand.RandomState.dirichlet
ValueError: alpha <= 0

NumPy/Python version information:

1.21.5

Context for the issue:

I have some applications where alpha(count|)-values are raw-data and zero is a very valid value. These applications worked with old versions of numpy but not with newer versions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions