Re: [Numpy-discussion] Indexing question

2021-05-20 Thread Sebastian Berg
On Thu, 2021-05-20 at 13:46 -0400, Robert Kern wrote: > On Thu, May 20, 2021 at 1:40 PM CJ Carey > wrote: > > If NEP 21 is accepted ( > > https://numpy.org/neps/nep-0021-advanced-indexing.html) this would > > be > > even simpler: > > > > out.vindex[:, x] = 1 > > > > Was there ever a decision

Re: [Numpy-discussion] Indexing question

2021-05-20 Thread Robert Kern
On Thu, May 20, 2021 at 1:40 PM CJ Carey wrote: > Or as a one-liner: > > out[np.arange(len(x)), x] = 1 > Ah, right. `x[arange(len(x))]` is a no-op. > If NEP 21 is accepted ( > https://numpy.org/neps/nep-0021-advanced-indexing.html) this would be > even simpler: > > out.vindex[:, x] = 1 > > Was

Re: [Numpy-discussion] Indexing question

2021-05-20 Thread CJ Carey
Or as a one-liner: out[np.arange(len(x)), x] = 1 If NEP 21 is accepted ( https://numpy.org/neps/nep-0021-advanced-indexing.html) this would be even simpler: out.vindex[:, x] = 1 Was there ever a decision about that NEP? I didn't follow the discussion too closely at the time. On Thu, May 20, 20

Re: [Numpy-discussion] interval wrapping / remainder / angle normalization

2021-05-20 Thread Thomas Hilger
When I understand correctly and what you desire is equivalent to integer overflowing, the function can indeed be applied as well. I tested. But to be sure, maybe some examples are better. Am Do., 20. Mai 2021 um 03:22 Uhr schrieb ZinGer_KyoN : > I have similar needs, but for int array and integer

Re: [Numpy-discussion] Indexing question

2021-05-20 Thread Neal Becker
Thanks! On Thu, May 20, 2021 at 9:53 AM Robert Kern wrote: > > On Thu, May 20, 2021 at 9:47 AM Neal Becker wrote: >> >> This seems like something that can be done with indexing, but I >> haven't found the solution. >> >> out is a 2D array is initialized to zeros. x is a 1D array whose >> values

Re: [Numpy-discussion] Indexing question

2021-05-20 Thread Robert Kern
On Thu, May 20, 2021 at 9:47 AM Neal Becker wrote: > This seems like something that can be done with indexing, but I > haven't found the solution. > > out is a 2D array is initialized to zeros. x is a 1D array whose > values correspond to the columns of out. For each row in out, set > out[row,x

[Numpy-discussion] Indexing question

2021-05-20 Thread Neal Becker
This seems like something that can be done with indexing, but I haven't found the solution. out is a 2D array is initialized to zeros. x is a 1D array whose values correspond to the columns of out. For each row in out, set out[row,x[row]] = 1. Here is working code: def orthogonal_mod (x, nbits)