[Numpy-discussion] help with translating some matlab

Neal Becker ndbecker2 at gmail.com
Fri Feb 18 13:50:49 EST 2011


Neal Becker wrote:

> My translation is:
> 
>     x1 = rcv[n:n-N:-1]
>     
>     z = np.dot (P, x1.conj().transpose())
> 
>     g = z / (_lambda + np.dot (x1, z))
> 
>     y = np.dot (h, x1.conj().transpose())
> 
>     e = x[n-N/2] - y
> 
>     h += np.dot (e, g.conj().transpose())
> 
>     P = (P - np.dot (g, z.conj().transpose()))/_lambda
> 
> But it doesn't work.
> 
> You say z should be a column vector.  I got:
> In [138]: x1.shape
> Out[138]: (64,)
> 
> In [139]: z.shape
> Out[139]: (64,)
> 
> Clearly, I did something wrong here.

I think I've got it.  In numpy, a 'vector' is a row vector.  If I want to turn a 
row vector into a column vector, transpose doesn't work.  I need to use newaxis 
for that.  So the whole translation is:

    x1 = rcv[n:n-N:-1]
    
    z = np.dot (P, x1.conj()[:,np.newaxis])

    g = z / (_lambda + np.dot (x1, z))

    y = np.dot (h, x1.conj()[:,np.newaxis])

    e = x[n] - y
    
    h += np.dot (e, g.conj().transpose())

    P = (P - np.dot (g, z.conj().transpose()))/_lambda





More information about the NumPy-Discussion mailing list