Numpy combine channels

MRAB python at mrabarnett.plus.com
Mon Sep 10 16:11:46 EDT 2012


On 10/09/2012 20:39, Wanderer wrote:
> I have an array generated by audiolab of left and right stereo
> channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine
> the left and right channels to get an array [2,3,5]. Is there a numpy
> command to do that?
>
>>> import numpy
>>> numpy.array([[1,1],[1,2],[2,3]], dtype="i")
array([[1, 1],
        [1, 2],
        [2, 3]])
>>> a[:, 0]
array([1, 1, 2])
>>> a[:, 1]
array([1, 2, 3])
>>> a[:, 0] + a[:, 1]
array([2, 3, 5])

But should they be added together to make mono?

Suppose, for example, that both channels have a maximum value. Their
sum would be _twice_ the maximum.

Therefore, I think that it should probably be the average.

 >>> (a[:, 0] + a[:, 1]) / 2
array([1, 1, 2])



More information about the Python-list mailing list