[Numpy-discussion] help with translating some matlab

Warren Weckesser warren.weckesser at enthought.com
Fri Feb 18 11:16:53 EST 2011


On Fri, Feb 18, 2011 at 10:04 AM, Neal Becker <ndbecker2 at gmail.com> wrote:

> I got the following matlab code from a colleage:
>
> initialization:
>
> h =zeros(1, N);  %%  initial filter coefficients
> lambda =1;
> delta =0.001;
>
> P =eye(N)/delta;
>
> loop:
>
> z =P*(x1');
>
> g =z/(lambda+ x1*z);
>
> y = h*x1';  %% filter output
>
> e = ph_cpm_out(n) - y; %% error
>
> h = h + e*g';   %% adaptation
>
> Pnext=(P-g*z')/lambda;
>
> P =Pnext;
>
> So it looks to me:
> z is a vector
>
> The step g=z/(lambda+x1*z) seems to be a vector division.
> How do I translate this to numpy?
>


It looks like x1 is a row vector and z is a column vector, so x1*z is a
scalar.

With numpy, something like

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

should work.

Warren



>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110218/f93a5e8f/attachment.html>


More information about the NumPy-Discussion mailing list