title: Finding shuffled column indices
body: <p>I have a bit of a weird problem of relating 2 numpy matrices (2d-arrays) to another. I think the problem is best described as having two matrices <code>A</code> and <code>B</code> for which B's indices of the axis=1 have been shuffled (the values of <code>A</code> and <code>B</code>, the position along the column axis (=1) is just different). What I am trying to find is the index map <em>m</em> for which <code>A[:,m] == B</code> so I know which column in <code>B</code> relates to which column in <code>A</code>.</p>
  <p>Here is an example (given <code>a</code> and <code>b</code>, I'd like to find <code>m</code>):</p>
  <pre><code>&gt;&gt;&gt; import numpy as np
  &gt;&gt;&gt; a = np.random.rand(70, 300)
  # we set up `m` to demonstrate the issue, but in fact that's not given
  &gt;&gt;&gt; m = np.asarray(list(range(300)))
  &gt;&gt;&gt; m
  array([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,
          13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,
          26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,
          39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51,
          52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,
          65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,
          78,  79,  80,  81,  82,  83,  84,  85,  86,  87,  88,  89,  90,
       ...
  &gt;&gt;&gt; np.random.shuffle(m)
  &gt;&gt;&gt; m
  array([209, 198,  17, 150, 181, 169,  47,  29, 109, 137, 149,   8,  85,
         251, 254, 191, 133,  40, 106, 243, 202, 101, 269,  23, 248,  49,
           3, 160,  88, 192, 166, 105, 283, 171, 128, 211, 206, 235, 185,
          37, 250,  66, 272, 259, 260,  14,  50, 256,  10, 238, 177,  15,
          51, 293,  53, 197,  11, 296, 111, 167,  86, 155, 215, 234,  80,
          76,  42, 216, 104, 144,  90,  45,  70, 126,  30, 117,   6, 139,
         299, 232, 182,  95, 129, 217,  55, 279, 118, 189, 180, 285, 157,
          79, 159, 294,  68, 244,  91,  52,  56, 127, 187, 131, 292, 164,
         132,  38,  87, 265, 173, 123, 154,  26, 143, 223, 276, 257, 263,
          93, 261, 179, 186, 267,  59, 221,  44,  31,  21,   9, 194,  25,
       ...
  &gt;&gt;&gt; b = a[:, m] # initialise `b`
  &gt;&gt;&gt; (a == b).all()
  False
  &gt;&gt;&gt; (b == a[:, m]).all()
  True
  </code></pre>
  <p>Another intricacy comes from the fact that the matrix is actually a little sparse which means there may be a number of possible versions of <em>m</em> (but I don't expect too many as the number of rows is relatively large and should limit the number of ambiguities).</p>