Python"这里,...在哪里"构建

And*_*tin 1 python numpy scipy pybrain

这是PyBrain网站的摘录.我得到了大部分内容,但有一条线让我完全难过.我之前从未在python代码中看到过这样的东西.对于上下文,这是整个循环:

    for c in [0, 1, 2]:
        #have no friggin idea how this next line works
        here, _ = where(tstdata['class']==c)
        plot(tstdata['input'][here, 0], tstdata['input'][here, 1], 'o')
Run Code Online (Sandbox Code Playgroud)

奇怪的"where"限定符来自NumPy,我得到了正在做的事情.我从来没有见过"这里"使用过这种方式.有人能解释一下这是做什么的吗?

Rap*_* K. 6

没有什么魔法,where是一个简单的函数,在其他地方定义,它返回两个元素的元组,并且赋值动作自动将它们解包为here变量和_变量.如果不是功能,where我们尝试简单tuple:

>>> here, _ = ("a", "b")
>>> here
'a'
>>> _
'b'
Run Code Online (Sandbox Code Playgroud)