title: Generating all permutations efficiently
body: <p>I need to generate as fast as possible all <a href="https://en.wikipedia.org/wiki/Permutation" rel="nofollow noreferrer">permutations</a> of integers <code>0</code>, <code>1</code>, <code>2</code>, <code>...</code>, <code>n - 1</code> and have result as a <a href="https://numpy.org/" rel="nofollow noreferrer">NumPy</a> array of shape <code>(factorial(n), n)</code>, or to iterate through large portions of such an array to conserve memory.</p>
  <p>Is there some built-in function in NumPy for doing this? Or some combination of functions.</p>
  <p>Using <code>itertools.permutations(...)</code> is too slow, I need a faster method.</p>