Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3858

Re: Pairwise frequency count from an incidence matrix of group membership

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=086d8ad5d=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.082
X-Spam-Evidence '*H*': 0.84; '*S*': 0.00; '(i.e.,': 0.03; 'def': 0.13; 'wrote:': 0.14; 'clues': 0.16; 'received:192.168.200': 0.16; 'val': 0.16; 'cc:no real name:2**0': 0.20; 'to:2**1': 0.20; 'cc:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:addr:python- list': 0.22; 'pair': 0.23; 'subject:group': 0.23; 'index': 0.25; 'hi,': 0.29; 'this.': 0.30; 'cc:addr:python.org': 0.31; '...': 0.32; 'data.': 0.33; 'received:192': 0.34; 'header:User-Agent:1': 0.35; 'data': 0.37; 'received:192.168': 0.37; 'some': 0.37; 'but': 0.38; 'members': 0.38; 'help': 0.39; 'set': 0.39; 'could': 0.39; 'how': 0.39; 'count': 0.40; 'best': 0.60; 'organized': 0.63; 'here': 0.65; 'share': 0.67; 'to:addr:yahoo.com': 0.83; 'incidence': 0.84; 'population.': 0.84; 'comprised': 0.91
X-IronPort-AV E=Sophos;i="4.64,253,1301868000"; d="scan'208";a="1290727"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Fri, 22 Apr 2011 12:57:38 +0200
From Jean-Michel Pichavant <jeanmichel@sequans.com>
User-Agent Mozilla-Thunderbird 2.0.0.24 (X11/20100328)
MIME-Version 1.0
To "Shafique, M. \(UNU-MERIT\)" <kmshafique@yahoo.com>
Subject Re: Pairwise frequency count from an incidence matrix of group membership
References <916949.47033.qm@web65408.mail.ac4.yahoo.com>
In-Reply-To <916949.47033.qm@web65408.mail.ac4.yahoo.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.742.1303469876.9059.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 82.94.164.166
X-Trace 1303469877 news.xs4all.nl 41110 [::ffff:82.94.164.166]:45356
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:3858

Show key headers only | View raw


Shafique, M. (UNU-MERIT) wrote:
> Hi,
> I have a number of different groups g1, g2, … g100 in my data. Each 
> group is comprised of a known but different set of members (m1, m2, 
> …m1000) from the population. The data has been organized in an 
> incidence matrix:
> g1 g2 g3 g4 g5
> m1 1 1 1 0 1
> m2 1 0 0 1 0
> m3 0 1 1 0 0
> m4 1 1 0 1 1
> m5 0 0 1 1 0
>
> I need to count how many groups each possible pair of members share 
> (i.e., both are member of). 
> I shall prefer the result in a pairwise edgelist with weight/frequency 
> in a format like the following:
> m1, m1, 4
> m1, m2, 1
> m1, m3, 2
> m1, m4, 3
> m1, m5, 1
> m2, m2, 2
> ... and so on.
>
> I shall highly appreciate if anybody could suggest/share some 
> code/tool/module which could help do this.
>
> Best regards,
> Muhammad
>
Here are some clues

m1 = [1,1,1,0,1]
m2 = [1,0,0,1,0]

def foo(list1, list2):
      return len([ index for index, val in enumerate(list1) if val and 
list2[index]])

 > foo(m1, m1)
< 4

 > foo(m1, m2)
< 1


JM

Back to comp.lang.python | Previous | NextNext in thread | Find similar


Thread

Re: Pairwise frequency count from an incidence matrix of group membership Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-04-22 12:57 +0200
  Re: Pairwise frequency count from an incidence matrix of group membership scattered <tooscattered@gmail.com> - 2011-04-22 07:43 -0700

csiph-web