Lets say I have a directory full of text files:
array1.txt
array2.txt
array3.txt
If I were to import a single text file using numpy, I'd do something like this:
array1 = numpy.loadtxt('filepath/array1.txt')
Notice that the numpy array has the same name as the text file it was created with (aside from .txt extension).
I'm not sure how to do someting like this in a loop though. Essentially, I want to look in the directory 'filepath'
, find every text file of the form name.txt
and load it as a numpy array which is named based on the name of the text file name
.
Thanks