Re: [Tutor] array and dictionary

2008-09-21 Thread Kent Johnson
On Sun, Sep 21, 2008 at 2:17 PM, Dinesh B Vadhia <[EMAIL PROTECTED]> wrote: > Given a (numpy) array how do you create a dictionary of lists where the list > contains the column indexes of non-zero elements and the dictionary key is > the row index. The easy way is 2 for loops ie. > > import numpy

Re: [Tutor] array and dictionary

2008-09-21 Thread Dinesh B Vadhia
help. Dinesh Message: 5 Date: Sun, 21 Sep 2008 09:15:00 +0100 From: "Alan Gauld" <[EMAIL PROTECTED]> Subject: Re: [Tutor] array and dictionary To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; format=flowed; charset="iso-8859-1"; r

Re: [Tutor] array and dictionary

2008-09-21 Thread Alan Gauld
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote Hi! Say, I've got a numpy array/matrix of the form: [[1 6 1 2 3] [4 5 4 7 0]... [2 1 0 5 6]] I want to create a dictionary of rows (as the keys) mapped to lists of non-zero numbers in that row Caveat, I dont know about numpy arrays.But assuming

Re: [Tutor] array and dictionary

2008-09-20 Thread Shantanoo Mahajan (शंत नू महा जन)
Straight forward method would be... >>> a=[[1],[2]] >>> b={} >>> for x in range(len(a)): ... b[x] = a[x] ... >>> a [[1], [2]] >>> b {0: [1], 1: [2]} >>> regards, shantanoo On 21-Sep-08, at 11:36 AM, Dinesh B Vadhia wrote: Hi! Say, I've got a numpy array/matrix of the form: [[1 6 1 2 3]