Reputation: 373
I have the following array:
prediction = [0 1 0 0 0 1 0 0 0 0 0 1 1 1 1 1 0 0 1 0]
I am looping over images in a test dataset, and what I want is for each image, to get the corresponding prediction. So for example, for image1 the prediction would be 0, for image2 it would be 1 etc.
I've been trying something like this, I know it's wrong but it gives you an idea of what I want:
clf = svm.SVC(kernel='linear', C=100)
for file in glob.glob(test_path + "/*.jpg"):
.
.
.
prediction = clf.predict(X_test)
for i in prediction:
prediction = prediction[i]
print(prediction)
(I've omitted the part of the code that isn't relevant, but if you need to see it i'll edit the post and add it in)
Is there a way to do what I'm asking?
Thanks in advance!
Upvotes: 2
Views: 372
Reputation: 7922
You can do:
for index,file in enumerate(glob.glob(test_path + "/*.jpg")):
prediction[index] #your prediction for the indexth image
This works for any iterable:
for i, each in enumerate(iterable):
print('The'+str(i)+'th element in your iterable is'+str(each))
Upvotes: 4