tags:

views:

65

answers:

2

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]
A: 

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

jschulenklopper
Ofri Raviv
The logical and operator in Python is `and`.
Xavier Ho
It makes no sense anyway. the return value of (A[:,0]==origin) is an array of booleans. You can't do a logical AND on two arrays.
Ofri Raviv
Ray
+1  A: 

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.

Ofri Raviv