The reason you can't use fill_value=[]
is hidden in the docs:
In the docs, it says that np.full
's fill_value
argument is either a scalar or array-like. In the docs for np.asarray
, you can find their definition of array-like:
Input data, in any form that can be converted to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays.
So, lists are treated specially as "array" fill types and not scalars, which is not what you want. Additionally, arr.fill([])
is actually not what you want, since it fills every element to the same list, which means appending to one appends to all of them. To circumvent this, you can do that this answer states, and just initialize the array with a list:
arr = np.empty(6, dtype=object)
arr[...] = [[] for _ in range(arr.shape[0])]
which will create an array with 6 unique lists, such that appending to one does not append to all of them.