[Numpy-discussion] help with translating some matlab
Warren Weckesser
warren.weckesser@enthought....
Fri Feb 18 13:23:20 CST 2011
On Fri, Feb 18, 2011 at 12:50 PM, Neal Becker <ndbecker2@gmail.com> wrote:
> 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
>
>
Sure, you can implement Matlab's row and column vectors that way. I would
probably stick with true 1D arrays (rather than Nx1 2D arrays), and
implement those lines something like this:
x1 = rcv[n:n-N:-1]
z = np.dot(P, x1.conj())
g = z / (_lambda + np.dot(x1, z))
y = np.vdot(x1, h)
e = x[n] - y
# Note: e is a scalar.
h += e * g.conj()
P = (P - np.outer(g, z.conj()))/_lambda
Note the use of vdot(); vdot(a,b) conjugates a and then dots with b. Also
note the use of outer() in the line that updates P.
Warren
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110218/96eb8d29/attachment.html
More information about the NumPy-Discussion
mailing list