title: Given a matrix, how can I quickly generate all tuples consisting of its row elements in python?
body: <p>Suppose there is a matrix:</p>
  <p><a href="https://i.stack.imgur.com/qYdfk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qYdfk.png" alt="enter image description here" /></a></p>
  <p>Next, I take an arbitrary element from each row of the matrix, since the matrix has <strong>m</strong> rows in total, I end up with <strong>m</strong> elements.</p>
  <p>After that, I arrange these elements together to form a tuple according to the row number from small to large, that is</p>
  <p><a href="https://i.stack.imgur.com/1jPoZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1jPoZ.png" alt="enter image description here" /></a></p>
  <p>Obviously, there are <strong>2^m</strong> such tuples in total. For example, when m=2, we will have 4 tuples, which are:</p>
  <p><a href="https://i.stack.imgur.com/63yBL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/63yBL.png" alt="enter image description here" /></a></p>
  <p>So, how can I program to generate these 2^m tuples quickly(In python)? Which algorithm should I use?</p>
  <hr />
  <p><strong>Note:</strong></p>
  <p>Input: An m×2 matrix</p>
  <p>Output: 2^m tuples</p>