Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #71975
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Subject | Re: Numpy Array of Sets |
| Date | 2014-05-24 23:14 +0100 |
| References | <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10272.1400969687.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Numpy Array of Sets Luis José Novoa <luisjosenovoa@gmail.com> - 2014-05-24 15:05 -0700
Re: Numpy Array of Sets Robert Kern <robert.kern@gmail.com> - 2014-05-24 23:14 +0100
Re: Numpy Array of Sets Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-05-25 00:25 +0200
Re: Numpy Array of Sets LJ <luisjosenovoa@gmail.com> - 2014-05-25 05:29 -0700
Re: Numpy Array of Sets Peter Otten <__peter__@web.de> - 2014-05-25 15:26 +0200
Re: Numpy Array of Sets LJ <luisjosenovoa@gmail.com> - 2014-05-25 07:14 -0700
Re: Numpy Array of Sets Peter Otten <__peter__@web.de> - 2014-05-25 17:12 +0200
Re: Numpy Array of Sets LJ <luisjosenovoa@gmail.com> - 2014-05-25 08:17 -0700
csiph-web