Reputation: 177
What I want to do, is to create a numpy array having 1 row and 3 coulmns.
Now I want to fill up the array, such that every element of the array are arrays themselves. And not only that, the sizes of each array (which are the elements of the bigger array) are different.
the first element has a size 1*m the second element has a size 1*n and so on ..
Upvotes: 0
Views: 4843
Reputation: 25023
You can initialize an empty Numpy array using np.empty
With the provision that the elements that you are going to assign are itself Numpy arrays (that is, objects) you shall use the dtype=object
as an optional argument to np.empty
.
In [72]: np.empty((1,3), dtype=object)
Out[72]: array([[None, None, None]], dtype=object)
Now we put a name on it and assign an array to one of its elements
In [73]: a = np.empty((1,3), dtype=object)
In [74]: a[0,1]=np.array((1,2,3,4,5))
and eventually we check that you've got what you've asked for...
In [75]: a
Out[75]: array([[None, array([1, 2, 3, 4, 5]), None]], dtype=object)
Is this what you want?
I'd like to add that what you want to do is likely better done using a list of Numpy arrays.
Upvotes: 4