Sir I have tried a similar thing initially, But then how to write these two files using indexes?
The source file named ‘total_list.txt’ is created in same script. I have closed it,
Then open it, the train val ids are there but from source file I need to extract those lines with corresponding Idx into two text files. I have tried this
fid_train=open('meta/training1.txt','w')
fid_test = open('meta/testing1.txt','w')
f1=open("meta/total_list.txt").readlines()
lines = [a for a in range(100)]
idx = torch.randperm(len(lines))
idx_train = idx[:int(0.8*len(idx))]
idx_val = idx[int(0.8*len(idx)):]

for lines in f1:
    fid_test.write(f1[idx_val])
    
fid_test.close()

for lines in f1:
    fid_train.write(f1[idx_train])
    
fid_train.close()    

but it throws error :only integer tensors of a single element can be converted to an index
Also replaced f1 with lines ,
for lines in f1:
    fid_test.write(lines[idx_val])
    
fid_test.close()


I am not getting this error actually why it says only integer tensors … all indexes are integer only.
Thanks for reply