Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6265
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'subject:using': 0.04; 'memory.': 0.05; 'not?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'underlying': 0.09; 'pm,': 0.10; '>>>': 0.12; 'wrote:': 0.14; '(0,': 0.16; '(1,': 0.16; '(2,': 0.16; 'enigma': 0.16; 'kern': 0.16; 'left-hand': 0.16; 'numpy': 0.16; 'propagate': 0.16; 'received:austin.res.rr.com': 0.16; 'subject:arrays': 0.16; 'subject:numpy': 0.16; 'header:In-Reply-To:1': 0.21; 'trying': 0.23; 'mask': 0.23; 'structured': 0.23; 'values': 0.25; 'object': 0.26; 'interpret': 0.29; 'array': 0.30; 'changes': 0.30; 'yet': 0.32; 'expression': 0.32; 'header:X-Complaints-To:1': 0.32; 'does': 0.33; 'to:addr:python-list': 0.33; 'actually': 0.33; 'header:User-Agent:1': 0.35; 'assignment': 0.35; 'list:': 0.36; 'received:rr.com': 0.36; 'skip:. 10': 0.36; 'change': 0.37; 'received:org': 0.38; 'could': 0.38; 'hello,': 0.38; 'url:org': 0.38; 'mailing': 0.38; 'though': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'attempt': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'final': 0.60; 'back': 0.63; 'world': 0.63; 'our': 0.63; 'view': 0.66; 'believe': 0.66; 'eco': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Robert Kern <robert.kern@gmail.com> |
| Subject | Re: using masks and numpy record arrays |
| Date | Wed, 25 May 2011 16:22:50 -0500 |
| Organization | The Church of Last Thursday |
| References | <irjon7$883$1@news.jpl.nasa.gov> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | cpe-70-113-40-77.austin.res.rr.com |
| User-Agent | Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 |
| In-Reply-To | <irjon7$883$1@news.jpl.nasa.gov> |
| 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.2095.1306358584.9059.python-list@python.org> (permalink) |
| Lines | 47 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1306358584 news.xs4all.nl 49046 [::ffff:82.94.164.166]:43965 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:6265 |
Show key headers only | View raw
On 5/25/11 3:27 PM, Catherine Moroney wrote:
> Hello,
>
> I am trying to work with a structured array and a mask, and am encountering some
> problems.
You will want to ask numpy questions on the numpy mailing list:
http://www.scipy.org/Mailing_Lists
> For example:
>
> >>> xtype = numpy.dtype([("n", numpy.int32), ("x", numpy.float32)])
> >>> a = numpy.zeros((4), dtype=xtype)
> >>> b = numpy.arange(0,4)
> >>> a2 = numpy.zeros((4), dtype=xtype)
> >>> mask = numpy.where(b%2 == 0)
> >>> a2[:]["n"] += b ! this changes the values of a2
> >>> a[mask]["n"] += b[mask] ! this does not change the values of a
> >>> a2
> array([(0, 0.0), (1, 0.0), (2, 0.0), (3, 0.0)],
> dtype=[('n', '<i4'), ('x', '<f4')])
> >>> a
> array([(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)],
> dtype=[('n', '<i4'), ('x', '<f4')])
>
> Why do the values of a2 get updated, and yet the values of a do not?
Only the final [] on the left-hand side of the assignment actually turns into a
.__setitem__() call to the object that is the result of the expression to its
left. a[mask] makes a copy while a2[:] makes a view.
You could do
a["n"][mask] += b[mask]
since a["n"] will also make a view and the .__setitem__() on it will propagate
back to the original memory.
--
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 | Find similar | Unroll thread
using masks and numpy record arrays Catherine Moroney <Catherine.M.Moroney@jpl.nasa.gov> - 2011-05-25 13:27 -0700 Re: using masks and numpy record arrays Robert Kern <robert.kern@gmail.com> - 2011-05-25 16:22 -0500
csiph-web