Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: numpy.full does not fill all types of data #5972

Open
jerasman opened this issue Jun 16, 2015 · 6 comments
Open

BUG: numpy.full does not fill all types of data #5972

jerasman opened this issue Jun 16, 2015 · 6 comments

Comments

@jerasman
Copy link

doesnt work

v= numpy.full(shape, [], dtype='object')

works

v=numpy.empty(shape, dtype='object')
v.fill([])

@ewmoore
Copy link
Contributor

ewmoore commented Jul 1, 2015

Yes. ndarray.fill fills will a scalar, but np.full can do more complicated fills and coerces its second argument to an array. So for instance, this means that

In [21]: np.full((6,2), [1,2])
Out[21]: 
array([[ 1.,  2.],
       [ 1.,  2.],
       [ 1.,  2.],
       [ 1.,  2.],
       [ 1.,  2.],
       [ 1.,  2.]])

works, but it cannot create an object array filled with an empty list.

Looking at the docstring for np.full its not obvious to me that this was by design, since it says fill_value : scalar, but this is how it works in practice. The docs could be improved here, since it really takes array_like input.

@ewmoore
Copy link
Contributor

ewmoore commented Jul 1, 2015

Broadcasting of the fill value is also untested, so seems unintentional.

@jerasman
Copy link
Author

jerasman commented Jul 1, 2015

Also, with
v=numpy.empty((3,3), dtype='object')
v.fill([])
v[0,0].extend([1])
extend() changes all the elements of the object array.

I wonder if there is functionality that can be added to fill/full that would avoid extra code like
filler=numpy.frompyfunc(list, 0, 1)
filler(v)
to fill an object array with empty lists that are not the same in memory.

@sursu
Copy link

sursu commented Nov 6, 2019

Might be wrong, but I think one can achieve that with: np.tile(list, shape)

@eric-wieser
Copy link
Member

@ewmoore: Created #14387 to track documenting the broadcasting

@vmarkovtsev
Copy link

np.tile(list, shape) does not work:

In [3]: np.tile([], 5)                                                                                                                                                
Out[3]: array([], dtype=float64)

@InessaPawson InessaPawson changed the title numpy.full does not fill all types of data BUG: numpy.full does not fill all types of data Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Object arrays
Awaiting triage
Development

No branches or pull requests

5 participants