【发布时间】:2020-01-15 14:39:07
【问题描述】:
我正在处理来自麦克风的信号。我的输入只是列表中的 12 个值,我必须以某种方式预处理。但我在这里找到的唯一一种解决方案就是使用多个 if 块。
mic.init()
while True:
mic_map = mic.get_map()
print(len(mic_map[:]))
b = mic.get_dir(mic_map)
if b[0]:
print("-90 degree")
pass
elif b[1]:
print("-60 degree")
pass
elif b[2]:
print("-30 degree")
pass
elif b[3]:
print("0 degree")
pass
elif b[4]:
print("+30 degree")
pass
elif b[5]:
print("+60 degree")
pass
elif b[6]:
print("+90 degree")
pass
elif b[7]:
print("+120 degree")
pass
elif b[8]:
print("+150 degree")
pass
elif b[9]:
print("+-180 degree")
pass
elif b[10]:
print("-150 degree")
pass
elif b[11]:
print("-120 degree")
pass
这里有没有可能做出更好的解决方案。谢谢。
UPD。很抱歉没有提供有关某些方法的必要信息。
mic.get_map() 正在返回一个包含 256 个值的列表,例如图像。
mic.get_dir() 返回一个包含 12 个值的列表。
【问题讨论】:
-
删除 if 和 elifs 中的每个
pass -
创建一个你想打印的东西的数组,然后用索引循环迭代它
-
b看起来像什么?这个mic是从哪里来的?
标签: python python-3.x