I have a Xmatrix of Row=12584 and Col 784. I want to extract each row based on another Tmatrix of Row=12584 Col 1 and append the values to numpy array X1 or X2. Even with smaller row size of 1500 it takes over 10 mins. I am sure there is better and efficient way to extract entire row and append to an array
import numpy as np
import time
start_time = time.time()
Row = 12584
#Row = 1500
Col = 784
Xmatrix = np.random.rand(Row,Col)
Tmatrix = np.random.randint(1,3,(Row,1))
X1 = np.array([])
X2 = np.array([])
for i in range(Row):
if Tmatrix[i] == 1:
for y in range(Col):
print ('Current row and col are --', i, y, Xmatrix[i][y])
X1 = np.append(X1, Xmatrix[i][y])
else:
for y in range(Col):
X2 = np.append(X2, Xmatrix[i][y])
print (X1)
print("--- %s seconds ---" % (time.time() - start_time))