I have a large text file with labels 0 or 1 in each line like this:
1
0
0
1
...
I load it, convert it into a numpy array, and then I want to convert the array into dtype=int64 (as I assume these are strings). I do it like this:
def load_data(infile):
text_file = open(infile,'r')
text = text_file.readlines()
text = map(str.strip,text)
return text
labels = load_data('labels.txt')
labels_encoded = np.array(labels)
labels_encoded = labels_encoded.astype(int)
It works fine in Python 2.7, and I can work on the array later with my code, but for now I'm stuck with Python 3.6 and when I ran my code, I get an error:
Traceback (most recent call last):
File "dText.py", line 77, in <module>
labels_encoded = labels_encoded.astype(int)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'map'
Can anyone help me figure out what is going on here and how to get it to work on Python 3.6? I also tried:
labels_encoded = np.int_(labels_encoded)
but I got the same error. I'm using numpy version 1.13.3. Thanks.
mapreturns? Are you sure?