python - Group overlapping arrays -


I have a list of the arrays, which I want to put in the group of overlapping values. My motivation is to use itertools.group, but I'm not sure how it works.

Some sample data:

  a = np.array (category (10)) b = np.array (category (90,100)) c = np.array (category (50,60)) d = np.array (range (815)) e = np.array (range (55,80  

I overlap (or non-narrow) arrays I want to end with three groups:

  groups = [[a, d], [b], [c, e]]  

Can I use itertools.groupby to do it?

For
 , g itertools.groupby ([A, b, c, d, e], lambda x: SOMETHING ?): Groups.append (list (g))  

But I'm not sure whether to sort and group Any suggestions that use this or any other method? Thanks!

Update:

Thank you for the solution given below @Bernart You are right that this There is not a large number of arrays, so killing the animals works just fine. I did this with the understanding of some clunky list:

X [0])) [ 0]): Group.Append (X), IDX.Append (n) Group.Append (group)

If your list of categories is quite small, then you can do it only by the force of the brute: check each boundary against a second range for overlap," merge "and every time you That seek to do so start the loop.

It is a bit useless to write with nodie arrays, so we use the (Python 3) range to get these ideas:

This is clearly a useless algorithm, but considering that you have to assign the variable to each There are some substantial objects, who cares? It should be easy to understand dead, and possibly more important here.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -