开发者

Simple numpy question

I can't get this snippet to work:

#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]


I'm practicing my Psychic debugging...

Your are missing parentheses in the last line:

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

should work.


Try replacing the logical AND operator & (which is a bitwise AND) by &&?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜