title: How to use a linear index to access a 2D array in Python
body: <p>I have one piece of code in MATLAB, and I try to translate that code to Python. In MATLAB, I can write this:</p>
  
  <pre><code>x = [1,2,3;4,5,6;7,8,9];
  </code></pre>
  
  <p>which is just a 3*3 matrix. Then if I use <code>x(1:5)</code>, MATLAB will first transfer the matrix <code>x</code> into a 1*9 vector and then return me a 1*5 vector as follows: <code>ans=[1,4,7,2,5];</code>
  So could you please tell me that what piece of simply code in python can have that same outcome?</p>