Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'mrab': 0.05; 'mask': 0.07; 'collections': 0.09; 'stable.': 0.09; 'arrays.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'observations': 0.16; 'pair,': 0.16; 'pairs': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'wrote:': 0.17; 'import': 0.21; 'combination': 0.22; 'task': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:b 30': 0.27; 'received:192.168.1.3': 0.29; 'array': 0.29; 'figure': 0.30; 'received:84': 0.32; 'subject:data': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'skip:b 20': 0.34; 'really': 0.36; 'but': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'apply': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'skip:a 30': 0.60; 'solve': 0.62; 'email addr:gmail.com': 0.63; 'results': 0.65; 'header:Reply- To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'counts': 0.81; 'reply-to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=FLuZNpUs c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=DKcI9XZsuF4A:10 a=6hwOr1HsOY8A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=pGLkceISAAAA:8 a=7Wak-EzF9BfvDTLWGGgA:9 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Tue, 24 Jul 2012 20:08:38 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: no data exclution and unique combination. References: <864b0104-daa8-4ea5-8003-6cfaab19fdea@googlegroups.com> <500EEEB6.1050904@mrabarnett.plus.com> In-Reply-To: <500EEEB6.1050904@mrabarnett.plus.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343156914 news.xs4all.nl 6849 [2001:888:2000:d::a6]:60390 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26003 On 24/07/2012 19:51, MRAB wrote: > On 24/07/2012 19:27, giuseppe.amatulli@gmail.com wrote: >> Hi, >> would like to take eliminate a specific number in an array and its correspondent in an other array, and vice-versa. >> >> given >> >> a=np.array([1,2,4,4,5,4,1,4,1,1,2,4]) >> b=np.array([1,2,3,5,4,4,1,3,2,1,3,4]) >> >> no_data_a=1 >> no_data_b=2 >> >> a_clean=array([4,4,5,4,4,4]) >> b_clean=array([3,5,4,4,3,4]) >> >> after i need to calculate unique combination in pairs to count the observations >> and obtain >> (4,3,2) >> (4,5,1) >> (5,4,1) >> (4,4,2) >> >> For the fist task i did >> >> a_No_data_a = a[a != no_data_a] >> b_No_data_a = b[a != no_data_a] >> >> b_clean = b_No_data_a[b_No_data_a != no_data_b] >> a_clean = a_No_data_a[a_No_data_a != no_data_b] >> >> but the results are not really stable. >> > mask = (a != no_data_a) & (b != no_data_b) > a_clean = a[mask] > b_clean = b[mask] > >> For the second task >> The np.unique would solve the problem if it can be apply to a two arrays. >> I couldn't figure out how to do the second part in numpy, so: from collections import Counter counts = Counter(zip(a_clean, b_clean)) counts = [pair + (count,) for pair, count in counts.items()]