8000 random.normal does not always preserve shape of size-1 arrays · Issue #7983 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
8000
random.normal does not always preserve shape of size-1 arrays #7983
Closed
@drhagen

Description

@drhagen

On 1.11.1, random.normal does not preserve the shape of its inputs in one particular case: the size of the ndarray is one.

In[2]: import numpy as np
In[2]: from numpy.random import normal

Sending in Python lists all acts as expected:

In[4]: normal(0)
Out[4]: -0.5191599213417067
In[5]: normal([0])
Out[5]: array([-0.03654451])
In[6]: normal([[0]])
Out[6]: array([[-1.03033527]])

Numpy arrays of size 1 all return a float instead of an array of the corresponding shape:

In[10]: normal(np.asarray(0))
Out[10]: 0.6874599652327416
In[11]: normal(np.asarray([0]))
Out[11]: -0.044433450447185156
In[12]: normal(np.asarray([[0]]))
Out[12]: -0.4610284419029141

Arrays of other shapes work fine:

In[14]: normal(np.asarray([0, 0]))
Out[14]: array([-0.58998342,  0.13144979])
In[15]: normal(np.asarray([[0, 0]]))
Out[15]: array([[-0.14003459,  0.28130253]])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0