Reputation: 1685
My objective is to start with an "empty" matrix and repeatedly add columns to it until I have a large matrix.
Upvotes: 1
Views: 432
Reputation: 97331
Add columns to ndarray(or matrix) need full copy of the content, so you should use other method such as list or the array module, or create a large matrix first, and fill data in it.
Upvotes: 2
Reputation: 28856
Yes:
>>> a = np.zeros((10, 0))
>>> a.shape
(10, 0)
You can then use ndarray.resize
to expand it after the fact without copying. This has some problems though, and for many applications it'll be easier to use a list of vectors that you then merge into a single array.
Upvotes: 3