First thing to point out, assuming My_Labels
is a list as you suggest, the indicated section of your code is superfluous:
def save_in_scv_format(My_Labels):
import numpy as np
K = [] # <--
for i in range(len(My_Labels)): # <--
K.append(My_Labels[i]) # <--
np.savetxt('My_labels.csv', K, delimiter = ',')
You'd be just as well off writing:
def save_in_scv_format(My_Labels):
import numpy as np
np.savetxt('My_labels.csv', My_Labels, delimiter = ',')
But I don't think you need numpy to do what it seems you want to do. Something like:
def save_in_scv_format(My_Labels):
with open('My_labels.csv', 'w') as f:
f.write(','.join(My_Labels))
would likely work, and better.
Alternatively, you could do something like:
def save_in_scv_format(My_Labels):
with open('My_labels.csv', 'w') as f:
f.write(str(My_Labels))
which would preserve the enclosing square brackets, and add spaces between the integers.
There is also the csv and pickle modules, you might look into, for alternative means of outputting your list to a file.
n.b. If I misunderstood, and My_Labels
is, for example, a numpy array, then something like:
my_array = My_Labels.tolist()
(docs) is a cleaner way of creating a python list.