There is no builtin function for this, but you could use senderle's cartesian_product or pv's cartesian function. Which is faster may depend on your use case. Then the following yields the desired result:
In [40]: cartesian_product([['z', 'q'], ['t', 'f']]).ravel().view('<U2')
Out[40]:
array(['zt', 'zf', 'qt', 'qf'],
dtype='<U2')
These functions can be faster than using itertools.product
. For example,
In [181]: x, y = np.arange(500), np.arange(500)
In [185]: %timeit cartesian_product([x, y])
1000 loops, best of 3: 797 µs per loop
In [184]: %timeit cartesian_product2([x, y])
1000 loops, best of 3: 1.44 ms per loop
In [186]: %timeit cartesian([x, y])
100 loops, best of 3: 4.71 ms per loop
In [100]: %timeit np.array(list(IT.product(x, y)))
10 loops, best of 3: 112 ms per loop