Input:
A string list like this:
['a', 'a', 'a', 'b', 'b', 'a', 'b']
Output I want:
A numpy array like this:
array([[ 1, 0],
[ 1, 0],
[ 1, 0],
[ 0, 1],
[ 0, 1],
[ 1, 0],
[ 0, 1]])
What I tried:
Try 1 - My starting data is actually stored in a column as a csv file. So I tried the following:
data1 = genfromtxt('csvname.csv', delimiter=',')
I did this because I thought I could manipulate the csv data into to form I want after I input it into the numpy format. However, the problem is I get all nan which is not a number. I'm not sure how else to go about this effectively because I need to do this for a large data set.
Try 2 - The ineffective method which I was thinking of doing:
For each element of the list, append [1,0] if a and append [0,1] if b.
Is there a better method?