Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100200 > unrolled thread
| Started by | Heli <hemla21@gmail.com> |
|---|---|
| First post | 2015-12-09 08:06 -0800 |
| Last post | 2015-12-10 19:55 +0000 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
np.searchSorted over 2D array Heli <hemla21@gmail.com> - 2015-12-09 08:06 -0800
Re: np.searchSorted over 2D array Peter Otten <__peter__@web.de> - 2015-12-09 17:36 +0100
Re: np.searchSorted over 2D array Heli <hemla21@gmail.com> - 2015-12-10 06:40 -0800
Re: np.searchSorted over 2D array Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-12-10 19:55 +0000
| From | Heli <hemla21@gmail.com> |
|---|---|
| Date | 2015-12-09 08:06 -0800 |
| Subject | np.searchSorted over 2D array |
| Message-ID | <2b660168-3322-4bf6-bd8b-2dc846a3a874@googlegroups.com> |
Dear all, I need to check whether two 2d numpy arrays have intersections and if so I will need to have the cell indices of the intersection. By intersection, I exactly mean the intersection definition used in set theory. I will give an example of what I need to do: a=[[0,1,2],[3,4,5],[6,7,8]] b=[[0,1,2],[3,4,5]] I would like to check whether b is subset of a and then get the indices in a where b matches. cellindices=[[True,True,True],[True,True,True],[False,False,False]] What is the best way to do this in numpy? Thanks in Advance for your help,
[toc] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2015-12-09 17:36 +0100 |
| Message-ID | <mailman.95.1449679003.12405.python-list@python.org> |
| In reply to | #100200 |
Heli wrote:
[Please don't open a new thread for the same problem]
> I need to check whether two 2d numpy arrays have intersections and if so I
> will need to have the cell indices of the intersection.
>
> By intersection, I exactly mean the intersection definition used in set
> theory.
>
> I will give an example of what I need to do:
>
> a=[[0,1,2],[3,4,5],[6,7,8]]
> b=[[0,1,2],[3,4,5]]
>
> I would like to check whether b is subset of a and then get the indices in
> a where b matches.
>
> cellindices=[[True,True,True],[True,True,True],[False,False,False]]
>
> What is the best way to do this in numpy?
Providing an example is an improvement over your previous post, but to me
it's still not clear what you want.
>>> functools.reduce(lambda x, y: x | y, (a == i for i in b.flatten()))
array([[ True, True, True],
[ True, True, True],
[False, False, False]], dtype=bool)
produces the desired result for the example input, but how do you want to
handle repeating numbers as in
>>> a = numpy.array([[0,1,2],[3,4,5],[3, 2, 1]])
>>> functools.reduce(lambda x, y: x | y, (a == i for i in b.flatten()))
array([[ True, True, True],
[ True, True, True],
[ True, True, True]], dtype=bool)
?
Try to be clear about your requirement, describe it in english and provide a
bit of context. You might even write a solution that doesn't use numpy and
ask for help in translating it.
At the very least we need more/better examples.
[toc] | [prev] | [next] | [standalone]
| From | Heli <hemla21@gmail.com> |
|---|---|
| Date | 2015-12-10 06:40 -0800 |
| Message-ID | <168a11ec-dd1e-481c-827b-8f5021a315cb@googlegroups.com> |
| In reply to | #100201 |
Thanks Peter, I will try to explain what I really need. I have a 3D numpy array of 100*100*100 (1M elements). Then I have another numpy array of for example 10*2*10 (200 elements). I want to know if in the bigger dataset of 100*100*100, there is anywhere, where the second numpy array of 200 elements with shape 10*2*10 appears. If it does, then I want the indices of the bigger dataset where this happens. I hope I´m making myself more clear :) Thanks for your comments, On Wednesday, December 9, 2015 at 5:37:07 PM UTC+1, Peter Otten wrote: > Heli wrote: > > [Please don't open a new thread for the same problem] > > > I need to check whether two 2d numpy arrays have intersections and if so I > > will need to have the cell indices of the intersection. > > > > By intersection, I exactly mean the intersection definition used in set > > theory. > > > > I will give an example of what I need to do: > > > > a=[[0,1,2],[3,4,5],[6,7,8]] > > b=[[0,1,2],[3,4,5]] > > > > I would like to check whether b is subset of a and then get the indices in > > a where b matches. > > > > cellindices=[[True,True,True],[True,True,True],[False,False,False]] > > > > What is the best way to do this in numpy? > > Providing an example is an improvement over your previous post, but to me > it's still not clear what you want. > > >>> functools.reduce(lambda x, y: x | y, (a == i for i in b.flatten())) > array([[ True, True, True], > [ True, True, True], > [False, False, False]], dtype=bool) > > produces the desired result for the example input, but how do you want to > handle repeating numbers as in > > >>> a = numpy.array([[0,1,2],[3,4,5],[3, 2, 1]]) > >>> functools.reduce(lambda x, y: x | y, (a == i for i in b.flatten())) > array([[ True, True, True], > [ True, True, True], > [ True, True, True]], dtype=bool) > > ? > > Try to be clear about your requirement, describe it in english and provide a > bit of context. You might even write a solution that doesn't use numpy and > ask for help in translating it. > > At the very least we need more/better examples.
[toc] | [prev] | [next] | [standalone]
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2015-12-10 19:55 +0000 |
| Message-ID | <mailman.120.1449777339.12405.python-list@python.org> |
| In reply to | #100235 |
On 10 Dec 2015 14:46, "Heli" <hemla21@gmail.com> wrote: > > Thanks Peter, > > I will try to explain what I really need. > > I have a 3D numpy array of 100*100*100 (1M elements). Then I have another numpy array of for example 10*2*10 (200 elements). I want to know if in the bigger dataset of 100*100*100, there is anywhere, where the second numpy array of 200 elements with shape 10*2*10 appears. If it does, then I want the indices of the bigger dataset where this happens. > So you want to find N in M. First find all occurrences of N[0][0][0] in M[:90][:98][:90]. Then for each of those extract the same size subview from M and check if (Ms == N).all(). -- Oscar
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web