I have a numpy array as:
prob_rf = [[0.4, 0.4, 0.4],
[0.5, 0.5, 0.5],
[0.6, 0.6, 0.6]]
I want to add an index number to each of the inner arrays as:
prob_rf = [[1, 0.4, 0.4, 0.4],
[2, 0.5, 0.5, 0.5],
[3, 0.6, 0.6, 0.6]]
and then save this array into a csv file using numpy.savetxt.
I am currently doing this as:
id = [i for i in xrange(1,len(prob)+1)]
prob_rf = np.insert(prob_rf, 0, id, axis=1)
np.savetxt("foo.csv", prob_rf, delimiter=",", fmt='%1.1f')
But this is giving the output as
[[1.0, 0.4, 0.4, 0.4],
[2.0, 0.5, 0.5, 0.5],
[3.0, 0.6, 0.6, 0.6]]
Could someone please tell me how do I get the output as
[[1, 0.4, 0.4, 0.4],
[2, 0.5, 0.5, 0.5],
[3, 0.6, 0.6, 0.6]]
fmt='%1.1f'if that's not what you want?[0.4, 0.4, 0.4]else np.savetext saves as[4.00E-01, 4.00E-01, 4.00E-01]which I don't want.