[Numpy-discussion] another indexing question

Robert Kern robert.kern at gmail.com
Mon May 20 12:03:55 EDT 2013


On Mon, May 20, 2013 at 5:00 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
> I have a system that transmits signals for an alphabet of M symbols
> over and additive Gaussian noise channel.  The receiver has a
> 1-d array of complex received values.  I'd like to find the means
> of the received values according to the symbol that was transmitted.
>
> So transmit symbol indexes might be:
>
> x = [0, 1, 2, 1, 3, ...]
>
> and receive output might be:
>
> y = [(1+1j), (1-1j), ...]
>
> Suppose the alphabet was M=4.  Then I'd like to get an array of means
>
> m[0...3] that correspond to the values of y for each of the corresponding
> values of x.
>
> I can't think of a better way than manually using loops.  Any tricks here?

All you need is a single loop over the alphabet, which is usually not
problematic.


means = np.empty([M])
for i in range(M):
    means[i] = y[x == i].mean()

--
Robert Kern



More information about the NumPy-Discussion mailing list