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


Groups > comp.lang.python > #108994

Re: numpy problem

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From lists@onemanifest.net
Newsgroups comp.lang.python
Subject Re: numpy problem
Date Mon, 23 May 2016 15:10:47 +0200
Lines 70
Message-ID <mailman.19.1464009073.20402.python-list@python.org> (permalink)
References <46F1751E-CA1E-4AB3-B6EB-589E1E2FD1D9@onemanifest.net> <nhusgg$vna$1@ger.gmane.org> <17D9C96A-C4EB-426F-A4A7-AA6492D7DBAB@onemanifest.net>
Mime-Version 1.0 (Mac OS X Mail 9.3 \(3124\))
Content-Type multipart/signed; boundary="Apple-Mail=_DF7E4C58-0CC7-4EE5-B798-E60B5E0923EF"; protocol="application/pgp-signature"; micalg=pgp-sha512
X-Trace news.uni-berlin.de RS5LgdpfIMSARGHL9p+cYQoroIhhX36Tyb0xmICkoFyA==
Return-Path <lists@onemanifest.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '16,': 0.03; 'column': 0.07; '75,': 0.09; 'indexes': 0.09; '100,': 0.16; '39,': 0.16; '57,': 0.16; '58,': 0.16; '60,': 0.16; '63,': 0.16; '64,': 0.16; 'filename:fname piece:signature': 0.16; 'from:addr:lists': 0.16; 'received:194.109': 0.16; 'received:194.109.24': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'row': 0.16; 'thx.': 0.16; 'values:': 0.16; 'wrote:': 0.16; 'subject:problem': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'values': 0.28; 'accomplished': 0.29; 'array': 0.29; '15,': 0.30; 'so,': 0.35; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'skip:v 20': 0.38; 'to:addr:python.org': 0.40; 'from:no real name:2**0': 0.60; 'header:Message-Id:1': 0.61; 'received:194': 0.61; 'skip:n 10': 0.62; '20,': 0.66; '81,': 0.84; '88,': 0.84; '92,': 0.84; 'otten': 0.84
X-Pgp-Agent GPGMail 2.6b2
In-Reply-To <nhusgg$vna$1@ger.gmane.org>
X-Mailer Apple Mail (2.3124)
X-Spam-Status No, score=-2.9 required=4.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.0
X-Spam-Checker-Version SpamAssassin 3.4.0 (2014-02-07) on mail01.onemanifest.net
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
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>
X-Mailman-Original-Message-ID <17D9C96A-C4EB-426F-A4A7-AA6492D7DBAB@onemanifest.net>
X-Mailman-Original-References <46F1751E-CA1E-4AB3-B6EB-589E1E2FD1D9@onemanifest.net> <nhusgg$vna$1@ger.gmane.org>
Xref csiph.com comp.lang.python:108994

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

> 
> On 23 mei 2016, at 14:19, Peter Otten <__peter__@web.de> wrote:
> 
> lists@onemanifest.net wrote:
> 
>> I've got a 2D array with values:
>> 
>> values = np.array(
>> [[ 20, 38,  4,  45, 65],
>> [ 81, 44, 38,  57, 92],
>> [ 92, 41, 16,  77, 44],
>> [ 53, 62,  9,  75, 12],
>> [ 58,  2, 60, 100, 29],
>> [ 63, 15, 48,  43, 71],
>> [ 80, 97, 87,  64, 60],
>> [ 16, 16, 70,  88, 80],
>> [ 19,  1, 73,  39, 97],
>> [ 48,  3, 27,  81, 14]])
>> 
>> And an array of indexes that for shows which row to keep for each column
>> of values:
>> 
>> keep = np.array([2, 3, 1, 9, 2])
>> 
>> So, the result should be an array like array([ values[2,0], values[3,1],
>> values[1,2], values[9,3], values[2,4] ]) == np.array([92, 62, 38, 81, 44])
>> 
>> Can this be accomplished in a vectorized manner?
> 
> How about
> 
> values[keep].diagonal()

That seems to do the trick!

Thx.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: numpy problem lists@onemanifest.net - 2016-05-23 15:10 +0200

csiph-web