I am computing features for images read from a directory and I want to write the image path and the corresponding features in a file, separated by spaces. The output is desired in this fashion
/path/to/img1.jpg 1 0 0 1 3.5 0.2 0
/path/to/img2.jpg 0 0 0.5 2.1 0 0.7
...
Following is part of my code
features.open('file.txt', 'w')
for fname in fnmatch.filter(fileList, '*.jpg'):
image = '/path/to/image'
# All the operations are here
myarray = [......] # array of dimensions 512x512
myarray.reshape(1, 512*512) # Reshape to make it a row vector
features.write(image + ' '.join(str(myarray)))
features.write('\n')
features.close()
But the output is coming as
/path/to/img1.jpg[[0 0 1.0 2 3]]
/path/to/img2.jpg[[1.2 0 1.0 2 0.3]]