简单的numpy问题

时间:2010-05-27 14:42:27

标签: python numpy

我无法让这个代码段工作:

#base code

A = array([ [ 1, 2, 10 ],
            [ 1, 3, 20 ],
            [ 1, 4, 30 ],
            [ 2, 1, 15 ],
            [ 2, 3, 25 ],
            [ 2, 4, 35 ],
            [ 3, 1, 17 ],
            [ 3, 2, 27 ],
            [ 3, 4, 37 ],
            [ 4, 1, 13 ],
            [ 4, 2, 23 ],
            [ 4, 3, 33 ] ])

# Number of zones
zones = unique1d(A[:,0])


for origin in zones:
  for destination in zones:
    if origin != destination:
      A_ik = A[(A[:,0] == origin & A[:,1] == destination), 2]

2 个答案:

答案 0 :(得分:1)

我正在练习我的心灵调试......

您在最后一行中缺少括号:

A_ik = A[(A[:,0] == origin) & (A[:,1] == destination), 2]

应该有用。

答案 1 :(得分:0)

尝试用&替换逻辑AND运算符&&(这是一个按位AND)?