Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1a.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'operator': 0.03; 'say,': 0.05; 'element': 0.07; 'great.': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'question.': 0.14; 'kern': 0.16; 'luis': 0.16; 'numpy': 0.16; 'operation,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'underlying': 0.16; 'url:faq': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'header:User- Agent:1': 0.23; 'interpret': 0.24; 'lets': 0.24; "shouldn't": 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'array': 0.29; 'robert': 0.30; 'sets': 0.30; 'anyone': 0.31; 'lists': 0.32; 'url:python': 0.33; 'add': 0.35; 'in:': 0.36; 'doing': 0.36; 'url:org': 0.36; 'list': 0.37; 'to:addr:python- list': 0.38; 'explain': 0.39; 'obtain': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'hope': 0.61; "you're": 0.61; 'our': 0.64; 'world': 0.66; 'believe': 0.68; 'results': 0.69; 'union': 0.69; 'as:': 0.81; 'eco': 0.84; 'subject:Sets': 0.84; 'terrible': 0.84; 'want:': 0.84; 'received:86': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: Numpy Array of Sets Date: Sat, 24 May 2014 23:14:32 +0100 References: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: cpc12-cmbg17-2-0-cust443.5-4.cable.virginm.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 In-Reply-To: <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1400969687 news.xs4all.nl 2863 [2001:888:2000:d::a6]:43376 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71975 On 2014-05-24 23:05, Luis José Novoa wrote: > Hi All, > > Hope you're doing great. One quick question. I am defining an array of sets using numpy as: > > a=array([set([])]*3) > > Now, if I want to add an element to the set in, lets say, a[0], and I use the .add(4) operation, which results in: > > array([set([4]), set([4]), set([4])], dtype=object) > > which I do not want. If I use the union operator > > a[0] = a[0] | set([4]) > > then I obtain what I want: > > array([set([4]), set([]), set([])], dtype=object) > > Can anyone explain whay this happens? Same reason why you shouldn't make a list of lists like so: [[]]*3 https://docs.python.org/2/faq/programming.html#how-do-i-create-a-multidimensional-list -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco