[英]Encoding a tuple of strings into integers
I'm trying to write by first Neural network from scratch using 2 inputs (length and width) to give the output (r/b). 我正在尝试使用2个输入(长度和宽度)从头开始从第一个神经网络编写输出(r / b)。 I want to encode the strings r and b into integers 0 and 1 so that I have an output vector. 我想将字符串r和b编码为整数0和1,以便有一个输出向量。 Without using a pre-made function like labelenconder. 不使用像labelenconder这样的预制函数。
length = np.array((3,2,4,3,3.5,2,5.5,1,4.5)) width = np.array((1.5,1,1.5,1,.5,.5,1,1,1)) c =('r','b','r','b','r','b','r','b','?')
Thanks in advance 提前致谢
You can do this fairly quickly like so: 您可以像这样快速完成此操作:
my_matcher = {'r':0, 'b':1}
new_input = [my_matcher.get(val) for val in c]
If you need it to be a tuple, you can wrap it with tuple(new_input)
如果需要将其作为元组,则可以将其包装为tuple(new_input)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.