我有一个函数,它可以获取浮点数的一比特热值,并且可以正常工作。现在,我必须将浮点值列表传递给另一个函数,该函数在该列表上进行迭代,并用等效的一比特位二进制值替换列表中的值。迭代功能仅更改列表中的第一个元素。我是python的新手,有人可以帮助或指导我采用正确的方法吗?
import decimal
import numpy as np
from ctypes import *
def one_hot_bit_val(x) :
#return answer
def one_hot_bit_List(myList) :
for n in range(0, len(myList)) :
myList[n] = one_hot_bit_val(myList[n])
return myList
B = [0.023, 0.0627, 0.0344, 0.0627]
print (one_hot_bit_List(B))
结果:
[0.015625、0.0627、0.0344、0.0627]
发生这种情况是因为您误输入了代码:
def one_hot_bit_List(myList) :
for n in range(0, len(myList)) :
myList[n] = one_hot_bit_val(myList[n])
return myList # <-- here
否则,您将在处理完第一个元素之后返回。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句