Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72012
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| 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.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'attribute': 0.07; 'modify': 0.07; 'modifying': 0.07; 'immutable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'set()': 0.16; 'elements': 0.16; 'modification': 0.16; 'prevent': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User- Agent:1': 0.23; '(for': 0.26; 'values': 0.27; 'header:X -Complaints-To:1': 0.27; 'reply.': 0.31; '"",': 0.31; 'assert': 0.31; 'fine,': 0.31; 'values.': 0.31; 'file': 0.32; '(most': 0.33; 'but': 0.35; 'there': 0.35; 'should': 0.36; 'example,': 0.37; 'so,': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'ensure': 0.60; 'skip:n 30': 0.60; "you're": 0.61; 'obvious': 0.74; 'or:': 0.84; 'subject:Sets': 0.84; 'canonical': 0.91; 'problems?': 0.91; 'trouble.': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Numpy Array of Sets |
| Date | Sun, 25 May 2014 17:12:25 +0200 |
| Organization | None |
| References | <38836877-cd87-44ce-b9df-1eda702e7164@googlegroups.com> <llr5k8$3n6$1@ger.gmane.org> <mailman.10273.1400970363.18130.python-list@python.org> <f55843c2-17f3-4551-a1c6-b608c09fd6d8@googlegroups.com> <mailman.10294.1401024422.18130.python-list@python.org> <9929f123-705c-4656-a400-171e48935244@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bd9f71.dip0.t-ipconnect.de |
| User-Agent | KNode/4.11.5 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10299.1401030762.18130.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1401030762 news.xs4all.nl 2902 [2001:888:2000:d::a6]:45149 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:72012 |
Show key headers only | View raw
LJ wrote:
> Thank you for the reply.
>
> So, as long as I access and modify the elements of, for example,
>
> A=array([[set([])]*4]*3)
>
>
> as (for example):
>
> a[0][1] = a[0][1] | set([1,2])
>
> or:
>
> a[0][1]=set([1,2])
>
> then I should have no problems?
As long as you set (i. e. replace) elements you're fine, but modifying means
trouble. You can prevent accidental modification by using immutable values
-- in your case frozenset:
>>> b = numpy.array([[frozenset()]*4]*3)
>>> b[0,0].update("123")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'frozenset' object has no attribute 'update'
Or you take the obvious approach and ensure that there are no shared values.
I don't know if there's a canonical form to do this in numpy, but
>>> a = numpy.array([[set()]*3]*4)
>>> a |= set()
works:
>>> assert len(set(map(id, a.flat))) == 3*4
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