[Numpy-discussion] MATLAB to Numpy

Paul Hobson pmhobson at gmail.com
Sat Oct 21 14:59:36 EDT 2017

```Can your provide representative examples for tmp_p[x|y|z]?
-paul

On Sat, Oct 21, 2017 at 10:45 AM, Andrei Berceanu <berceanu at runbox.com>
wrote:

> Hi,
>
> I am new to Numpy, and would like to start by translating a (badly
> written?) piece of MATLAB code.
> What I have come up with so far is this:
>
> px = np.zeros_like(tmp_px); py = np.zeros_like(tmp_py); pz =
> np.zeros_like(tmp_pz)
> w = np.zeros_like(tmp_w)
> x = np.zeros_like(tmp_x); y = np.zeros_like(tmp_y); z =
> np.zeros_like(tmp_z)
>
> j=-1
> for i in range(tmp_px.size):
>     if tmp_px[i] > 2:
>         j += 1
>         px[j] = tmp_px[i]
>         py[j] = tmp_py[i]
>         pz[j] = tmp_pz[i]
>         w[j] = tmp_w[i]
>         x[j] = tmp_x[i]
>         y[j] = tmp_y[i]
>         z[j] = tmp_z[i]
>
> px=px[:j+1]; py=py[:j+1]; pz=pz[:j+1]
> w=w[:j+1]
> x=x[:j+1]; y=y[:j+1]; z=z[:j+1]
>
> It works, but I'm sure it's probably the most inefficient way of doing it.
> What would be a decent rewrite?
>
> Thank you so much,
> Best regards,
> Andrei
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20171021/7497aea0/attachment.html>
```