0

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.

  • No, I don't know the number of elements in the feature_matrix. so it depends on my situation. Please open this question –  Sep 06 '17 at 01:25
  • `np.insert(feature_matrix,0,np.arange(len(feature_matrix)),axis=1)` – hpaulj Sep 06 '17 at 01:27
  • @hpaulj Thank you for the comment. Can you please tell me what happens here? –  Sep 06 '17 at 01:32
  • `column_stack` and `concatenate` can also be used. The same concept, just slight differences in how they handle the inputs. – hpaulj Sep 06 '17 at 03:31

0 Answers0