title: Matlab equivalent in Python: logical XOR on arrays of different lengths?
body: <p>I want to convert Matlab code which is doing an XOR on two vectors into Python. I have tried to do this using the numpy.logical_xor() function but this is failing because the two arrays being compared are not of the same shape, preventing broadcasting from working.</p>
  <p>The Matlab code I'm trying to emulate:</p>
  <pre><code>test5=setxor(1:length(test2(test3)),test4);
  </code></pre>
  <p>The current (non-working) attempt at the above in Python:</p>
  <pre><code>test5 = np.logical_xor(np.array(range(len(test2[test3]))), test4)
  </code></pre>
  <p>When this line executes I get the following error:</p>
  <pre><code>ValueError: operands could not be broadcast together with shapes (366217,) (120655,)
  </code></pre>
  <p>I also get the same result when I add an axis to each of the arrays using numpy.expand_dims(), I get messages such as</p>
  <pre><code>ValueError: operands could not be broadcast together with shapes (1, 366217) (1, 120655)
  ValueError: operands could not be broadcast together with shapes (366217,1) (120655,1)
  </code></pre>
  <p>The issue is the different lengths of test2[test3] and test4, and it seems that the Matlab setxor() functino works fine on vectors of different lengths but the numpy equivalent requires vectors of equal length.</p>
  <p>How can I perform an XOR on two 1-D numpy arrays of different lengths? Or perhaps I am misunderstanding what is happening in the Matlab code and/or using the wrong Python function for this?</p>