Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100201
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: np.searchSorted over 2D array |
| Date | Wed, 09 Dec 2015 17:36:31 +0100 |
| Organization | None |
| Lines | 47 |
| Message-ID | <mailman.95.1449679003.12405.python-list@python.org> (permalink) |
| References | <2b660168-3322-4bf6-bd8b-2dc846a3a874@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de GW8DBBEI1th6YgYpy4YA5QIcb+9GqB2Z+jo1EyPJV6qQ== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'true,': 0.04; 'false,': 0.07; 'indices': 0.07; 'input,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'thread': 0.10; 'intersection': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:array': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'arrays': 0.22; 'context.': 0.22; 'produces': 0.22; 'bit': 0.23; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'least': 0.27; 'subset': 0.29; 'open': 0.33; 'definition': 0.34; 'handle': 0.34; 'previous': 0.34; 'clear': 0.35; 'but': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'desired': 0.37; 'mean': 0.38; 'to:addr:python.org': 0.40; 'where': 0.40; 'still': 0.40; 'received:de': 0.40; 'your': 0.60; 'provide': 0.61; 'providing': 0.62; 'examples.': 0.84; 'post,': 0.84; 'subject:over': 0.84; 'subject:skip:n 10': 0.84; 'do:': 0.91; 'improvement': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd81bb.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:100201 |
Show key headers only | View raw
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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web