Extracting required indices from the array of tuples
import numpy as np from scipy import signal y = np.array([[2, 1, 2, 3, 2, 0, 1, 0], [2, 1, 2, 3, 2, 0, 1, 0]]) maximas = signal.argrelmax(y, axis=1) print maximas (array([0, 0, 1, 1], dtype=int64), array([3, 6, 3, 6], dtype=int64)) I want to extract only the first maxima of both rows, i.e., [3, 3] using the tuples (maximas). How would you do it?
On Fri, Jan 2, 2015 at 3:06 AM, Simen Langseth <simlangen@gmail.com> wrote:
import numpy as np from scipy import signal
y = np.array([[2, 1, 2, 3, 2, 0, 1, 0], [2, 1, 2, 3, 2, 0, 1, 0]])
maximas = signal.argrelmax(y, axis=1)
print maximas
(array([0, 0, 1, 1], dtype=int64), array([3, 6, 3, 6], dtype=int64))
I want to extract only the first maxima of both rows, i.e., [3, 3] using the tuples (maximas). How would you do it?
Something like this should work:
rows, cols = maximas first_in_row = np.concatenate(([True], rows[:-1] != rows[1:])) rows = rows[first_in_row] cols = cols[first_in_row] y[rows, cols] array([3, 3])
Jaime -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial.
Dear Jaime: Thank you so much. Your codes are always great. By the way, I have been waiting for several hours to get satisfactory answer at: http://codereview.stackexchange.com/questions/75457/faster-way-of-using-inte... http://stackoverflow.com/questions/27735832/faster-way-of-using-interp1d-in-... Please help me there if you have time. Simen On Fri, Jan 2, 2015 at 9:29 PM, Jaime Fernández del Río < jaime.frio@gmail.com> wrote:
On Fri, Jan 2, 2015 at 3:06 AM, Simen Langseth <simlangen@gmail.com> wrote:
import numpy as np from scipy import signal
y = np.array([[2, 1, 2, 3, 2, 0, 1, 0], [2, 1, 2, 3, 2, 0, 1, 0]])
maximas = signal.argrelmax(y, axis=1)
print maximas
(array([0, 0, 1, 1], dtype=int64), array([3, 6, 3, 6], dtype=int64))
I want to extract only the first maxima of both rows, i.e., [3, 3] using the tuples (maximas). How would you do it?
Something like this should work:
rows, cols = maximas first_in_row = np.concatenate(([True], rows[:-1] != rows[1:])) rows = rows[first_in_row] cols = cols[first_in_row] y[rows, cols] array([3, 3])
Jaime
-- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (2)
-
Jaime Fernández del Río
-
Simen Langseth