Re: [Numpy-discussion] MATLAB to Numpy

2017-10-21 Thread Daπid
On 21 October 2017 at 22:32, Eric Wieser wrote: > David, that doesn’t work, because np.cumsum(mask)[mask] is always equal > to np.arange(mask.sum()) + 1. Robert’s answer is correct. > Of course, you are right. It makes sense in my head now. ___ NumPy-Di

Re: [Numpy-discussion] MATLAB to Numpy

2017-10-21 Thread Eric Wieser
David, that doesn’t work, because np.cumsum(mask)[mask] is always equal to np.arange(mask.sum()) + 1. Robert’s answer is correct. Eric On Sat, 21 Oct 2017 at 13:12 Daπid wrote: On 21 October 2017 at 21:03, Robert Kern wrote: > >> Index with a boolean mask. >> >> mask = (tmp_px > 2) >> px = tmp

Re: [Numpy-discussion] MATLAB to Numpy

2017-10-21 Thread Daπid
On 21 October 2017 at 21:03, Robert Kern wrote: > Index with a boolean mask. > > mask = (tmp_px > 2) > px = tmp_px[mask] > py = tmp_py[mask] > # ... etc. > > That isn't equivalent, note that j only increases when tmp_px > 2. I think you can do it with something like: mask = tmp_px > 2 j_values =

Re: [Numpy-discussion] MATLAB to Numpy

2017-10-21 Thread Robert Kern
On Sat, Oct 21, 2017 at 10:45 AM, Andrei Berceanu 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)

Re: [Numpy-discussion] MATLAB to Numpy

2017-10-21 Thread Paul Hobson
Can your provide representative examples for tmp_p[x|y|z]? -paul On Sat, Oct 21, 2017 at 10:45 AM, Andrei Berceanu 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_li

[Numpy-discussion] MATLAB to Numpy

2017-10-21 Thread Andrei Berceanu
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_lik