another indexing question
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?
On Mon, May 20, 2013 at 5:00 PM, Neal Becker <ndbecker2@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
You could also try using bincount, (np.bincount(x, y.real) + 1j*np.bincount(x, y.imag)) / np.bincount(x) Bago On Mon, May 20, 2013 at 9:03 AM, Robert Kern <robert.kern@gmail.com> wrote:
On Mon, May 20, 2013 at 5:00 PM, Neal Becker <ndbecker2@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 _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (3)
-
Bago
-
Neal Becker
-
Robert Kern