title: Vectorize with a list of lists in Python
body: <p>My final goal is to use a vectorized numpy solution for a for-loop. This loop creates for each element a random sample from another list if its elements are not given in the original element. However, the for-loops' input is a list of lists. I do not know how to apply a numpy vectorization for a list of lists. A reproducible example is here:</p>
  <pre class="lang-py prettyprint-override"><code>import random
  
  list_of_all_items = [1, 2, 3, 4, 12, 21, 23, 42, 93]
  seen_formats = [[1, 2, 3, 4], [2,23, 21, 3], [12, 42, 93, 1]]
  
  
  not_seen_formats = []
  for seen in seen_formats:
      not_seen_formats.append(random.sample([format_ for format_ in list_of_all_items if format_ not in seen],
                              len(seen) * 1))
  </code></pre>
  <p>What I tried so far is:</p>
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  
  np.where(np.in1d(np.random.choice(list_of_all_items, 2, replace = False), np.asarray(seen_formats)))
  &gt;&gt; (array([0, 1], dtype=int64),)
  </code></pre>
  <p>This sadly makes no sense. What I would like to have returned is an array which should contain random samples for the given list of lists, like:</p>
  <pre class="lang-py prettyprint-override"><code>&gt;&gt; array([[12, 21], # those numbers should be random numbers
            [ 1,  4],
            [ 2,  3]])
  </code></pre>