How To Build A Matrix One Column At A Time
I am wanting to build some matrices one column at a time, with columns from an existing matrix, as per the code below. # x is an existing matrix, y is an array, pos_classes is a se
Solution 1:
You're going about this the wrong way. It's almost always better to do such things in a vectorized way in numpy.
First, build your index array y_pos_actual
. Then, simply do
x_pos = x[:, y_pos_actual]
This will select all columns given by the indices y_pos_actual
into a new matrix x_pos
. You can do the same row-wise using
x_pos = x[y_pos_actual, :]
Post a Comment for "How To Build A Matrix One Column At A Time"