[Numpy-discussion] Is there a pure numpy recipe for this?
Jaime Fernández del Río
jaime.frio at gmail.com
Wed Mar 26 16:58:52 EDT 2014
On Wed, Mar 26, 2014 at 1:28 PM, Slaunger <Slaunger at gmail.com> wrote:
See if you can make sense of the following. It is a little cryptic, but it
works:
f_change = np.array([2, 3, 39, 41, 58, 59, 65, 66, 93, 102, 145])
g_change = np.array([2, 94, 101, 146, 149])
N = 150
if len(f_change) % 2 :
f_change = np.append(f_change, N)
if len(g_change) % 2 :
g_change = np.append(g_change, N)
idx = np.searchsorted(f_change, g_change)
f_change_exp = np.insert(np.insert(f_change, idx, g_change),
idx + np.arange(len(idx)), g_change)
idx2 = np.searchsorted(g_change, f_change_exp)
f_change_lens = f_change_exp[1::2] - f_change_exp[::2]
true_true_intervals = idx2[1::2] % 2 != 0
total = np.sum(f_change_lens[true_true_intervals])
>>> total
9
I'll gladly elaborate on what's going on, just ask!
Jaime
--
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
de dominación mundial.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140326/9ddb7968/attachment.html>
More information about the NumPy-Discussion
mailing list