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


Groups > comp.lang.python > #108994 > unrolled thread

Re: numpy problem

Started bylists@onemanifest.net
First post2016-05-23 15:10 +0200
Last post2016-05-23 15:10 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#108994 — Re: numpy problem

Fromlists@onemanifest.net
Date2016-05-23 15:10 +0200
SubjectRe: numpy problem
Message-ID<mailman.19.1464009073.20402.python-list@python.org>

[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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web