Issue When Extending A Matrix-like Numpy Array By Adding Extra List
I wrote the following code that does: (1) Generate root matrix of shape (3, 16), and (2) Generate 1000 binary vectors C such that each vector is added at the end of the root matrix
Solution 1:
If you can swap this:
batch = root[i:(i + (len(root)))]
batch = np.append(batch, C[i])
For this:
batch = np.append(batch, [C[i]], axis=0)
axis
allows you to append two matrices on a particular dimension. So we make C[i]
into a matrix and append it in dimension 0.
I am not sure what the intention of this batch = root[i:(i + (len(root)))]
is but it shortens batch
to a matrix the size of root every time so it will not increase in size. It actually shrinks as you near the end of root
.
Also C is not always 1000 vectors. Making them unique removes some.
Post a Comment for "Issue When Extending A Matrix-like Numpy Array By Adding Extra List"