I have a numpy feature_matrix as below.
feature_matrix = [[0.1,0.3,0.5], [0.7,0.8,0.1]]
Now I want to add 0, 1, 2, so on at the beginning of this feature matrix as below.
altered_feature_matrix = [[0, 0.1,0.3,0.5], [1, 0.7,0.8,0.1]]
I tried to do it using np.insert. However, then I get a flat list.
for l in write_fw_feature_matrix:)
l=np.insert(l,[0],pos)
altered_feature_matrix = np.insert(altered_feature_matrix, l)
#print(l)
pos = pos+1
print(altered_feature_matrix)
Please help me to resolve my problem.
np.insert(feature_matrix,0,np.arange(len(feature_matrix)),axis=1)column_stackandconcatenatecan also be used. The same concept, just slight differences in how they handle the inputs.