Skip to content

dtype of np.random.choice differs with presence of p on windows #9867

Closed

Description

@jcrist

The dtype of the output of np.random.choice with a scalar a is different if p is provided on windows:

>>> import numpy as np
>>> p = np.array([0.5, 0.5])
>>> np.random.choice(2, size=1).dtype
dtype('int32')
>>> np.random.choice(2, p=p, size=1).dtype
dtype('int64')
>>> np.__version__
1.13.1

I'd expect the output dtype to be consistent whether p is present or absent. Since the dtype of arange on win32 is int32, the int64 dtype output is probably the incorrect one.

Activity

  1. bashtage commented on Oct 18, 2017

    @bashtage
    Contributor

    This difference occurs at

    https://github.com/numpy/numpy/blob/master/numpy/random/mtrand/mtrand.pyx#L1155

    since searchsorted returns int64 irrespective of platform.

  2. bashtage commented on Oct 18, 2017

    @bashtage
    Contributor

    The return type for searchsorted is NPY_INTP here:

    ret = (PyArrayObject *)PyArray_New(&PyArray_Type, PyArray_NDIM(ap2),

  3. bashtage commented on Jun 1, 2019

    @bashtage
    Contributor

    @mattip This is fixed in Generator but not in RandomState. Should it be fixed in RandomState or left as it was in 1.16?

  4. mattip commented on Jun 1, 2019

    @mattip
    Member

    I guess this is a bug, and should be fixed, unless it breaks something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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