Translate code matlab to python numpy
<p>I don't understand about matlab programming, I just understand coding in python...</p>

<p><img src="http://i.stack.imgur.com/ww2zr.jpg" alt="here my matrix want to solve "></p>

<h3>Matlab Code:</h3>

<pre><code> x = ones(3,1).
con = [0.505868045540458,0.523598775598299].
series = [1,2,3] 
for j = 1:2 
   #here stuck to translate Python code#
   x = [x cos(con(j)*series)' sin(con(j)*series)'];
end
</code></pre>

<h3>Result :</h3>

<pre><code>1.0000    0.8748    0.4846    0.8660    0.5000
1.0000    0.5304    0.8478    0.5000    0.8660
1.0000    0.0532    0.9986   -0.0000    1.0000
</code></pre>

<p>Anyone help me please, how to solve this problem...
Regards!</p>

<p>My recreation in an Ipython session (having first tested your code in an Octave session):</p>

<pre><code>In [649]: con = np.array([0.505868, 0.5235897])
In [650]: series = np.array([1,2,3])
In [651]: x = [np.ones((3,))]
In [652]: for j in range(2):
     ...:     x.extend([np.cos(con[j]*series), np.sin(con[j]*series)])
     ...:     
In [653]: x
Out[653]: 
[array([ 1.,  1.,  1.]),
 array([ 0.8747542 ,  0.53038982,  0.05316725]),
 array([ 0.48456691,  0.84775388,  0.99858562]),
 array([  8.66029942e-01,   5.00015719e-01,   2.72267949e-05]),
 array([ 0.49999214,  0.86601633,  1.        ])]
In [654]: np.array(x).T
Out[654]: 
array([[  1.00000000e+00,   8.74754200e-01,   4.84566909e-01,
          8.66029942e-01,   4.99992140e-01],
       [  1.00000000e+00,   5.30389821e-01,   8.47753878e-01,
          5.00015719e-01,   8.66016328e-01],
       [  1.00000000e+00,   5.31672464e-02,   9.98585622e-01,
          2.72267949e-05,   1.00000000e+00]])
</code></pre>

<p>In MATLAB the </p>

<pre><code>x = [x cos(...) sin(...)]
</code></pre>

<p>is closer to</p>

<pre><code>x = np.concatenate([x, cos(...), sin(...)], axis=?)
</code></pre>

<p>but in numpy list append (or in this case extend) is faster.  I just had to initial <code>x</code> to the appropriate list.</p>

<p>==================</p>

<p>I can get the same values without the loop</p>

<pre><code>In [663]: y = con[:,None]*series
In [664]: [np.cos(y), np.sin(y)]
Out[664]: 
[array([[  8.74754200e-01,   5.30389821e-01,   5.31672464e-02],
        [  8.66029942e-01,   5.00015719e-01,   2.72267949e-05]]),
 array([[ 0.48456691,  0.84775388,  0.99858562],
        [ 0.49999214,  0.86601633,  1.        ]])]
</code></pre>

<p>but it's a bit of a pain to rearrange them into the order produced by iteration, <code>[1, cos, sin, cos,  sin]</code>.</p>

python matlab numpy math computer-science