Re: How do you do arrays

2005-02-02 Thread Alex Martelli
Kartic <[EMAIL PROTECTED]> wrote: ... > I am not sure what book you are using but I don't think it is a very > good one. Hmmm, considering he said it's "Python in a Nutshell", I disagree with you;-). If he had understood that he probably wanted to use lists, not arrays, the top paragraph on p.

Re: How do you do arrays

2005-02-01 Thread Erik Max Francis
Dennis Lee Bieber wrote: Classic BASIC actually splits the difference. dim a(10) allocates 11 elements, indexed 0..10 -- but most classes tend to ignore element 0, and algorithms are as if only 10 elements exist starting at 1. Basic also has the OPTION BASE instruction, which affects that.

Re: How do you do arrays

2005-02-01 Thread Thomas Bunce
Thanks Tom In article <[EMAIL PROTECTED]>, "Dan Perl" <[EMAIL PROTECTED]> wrote: > A solution that I haven't seen mentioned by other postings in the thread is > to implement the array as a dictionary: > > iMatrix = {} > for index in range(majorlop1): > k = random.choice(listvalues) + 1 >

Re: How do you do arrays

2005-02-01 Thread Dan Perl
A solution that I haven't seen mentioned by other postings in the thread is to implement the array as a dictionary: iMatrix = {} for index in range(majorlop1): k = random.choice(listvalues) + 1 iMatrix[index] = k Mind you, a dictionary does not behave *exactly* like an array. For insta

Re: How do you do arrays

2005-02-01 Thread Thomas Bunce
It was when I saw a use of complex numbers as a usable statement I became interested in Python Tom In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > If you want do numerical calculations with vectors and matrices, you > should probably use the Numarray module. Python's built-i

Re: How do you do arrays

2005-02-01 Thread Thomas Bunce
Learning Python O'Reilly book and Python In A Nut Shell and about 2 inchs printed of Web information Tom In article <[EMAIL PROTECTED]>, "Kartic" <[EMAIL PROTECTED]> wrote: > Tom, > > It has to be iMatrix.append(k), not iMatrix[index] = k. Python will > give an error - list assignment in

Re: How do you do arrays

2005-02-01 Thread Kartic
Tom - I answered your question even before you posted it! You have to use iMatrix.append(k) and NOT iMatrix[index] = k. Also, what do you expect out of: while index < majorlop1: print '- %s %s' % ( iMatrix[index], sep) This loop will never get executed because your previous loop finishes due to

Re: How do you do arrays

2005-02-01 Thread beliavsky
wes weston wrote: > Thomas, > If you were allowed to do what you're doing, the > list first element would be getting skipped as "index" > is always > 0. The thing is, you don't want the "index" > var at all for adding to the list; just do jMatrix.append(k). > You can iterate over the list w

Re: How do you do arrays

2005-02-01 Thread wes weston
Thomas, If you were allowed to do what you're doing, the list first element would be getting skipped as "index" is always > 0. The thing is, you don't want the "index" var at all for adding to the list; just do jMatrix.append(k). You can iterate over the list with for x in jMatrix: print x

Re: How do you do arrays

2005-02-01 Thread Thomas Bunce
Tryed it and this is what I got (I did go to the web sight) tom(h=500)$ /tmp/501/Cleanup\ At\ Startup/ptesting-128981347.87.py.command; exit Input the maximu number of tvalue: 114 Traceback (most recent call last): File "/Users/tom/Desktop/ptesting.py", line 20, in ? iMatrix[index] = k Index

Re: How do you do arrays

2005-02-01 Thread beliavsky
If you want do numerical calculations with vectors and matrices, you should probably use the Numarray module. Python's built-in lists are not intended for heavy numerical computations. They are more flexible than the arrays in languages like C and Fortran in that they can store elements of differen

Re: How do you do arrays

2005-02-01 Thread Thomas Bunce
Thanks all Tom -- http://mail.python.org/mailman/listinfo/python-list

Re: How do you do arrays

2005-02-01 Thread Kartic
Tom, It has to be iMatrix.append(k), not iMatrix[index] = k. Python will give an error - list assignment index out of range - for that. Just curious - what book are you following? -Kartic -- http://mail.python.org/mailman/listinfo/python-list

Re: How do you do arrays

2005-02-01 Thread wes weston
Thomas Bunce wrote: I am new at Pyton and I am learning from book not classes so please forgive my being slow The below does not work I get an Error of File "Matrix[index] = k NameError: name 'iMatrix' is not defined" while index < majorlop1: index = index + 1 k = random.choice(listvalues

Re: How do you do arrays

2005-02-01 Thread Sean Blakey
On Tue, 01 Feb 2005 10:52:45 -0800, Thomas Bunce <[EMAIL PROTECTED]> wrote: > I am new at Pyton and I am learning from book not classes > so please forgive my being slow > > The below does not work I get an Error of File > "Matrix[index] = k > NameError: name 'iMatrix' is not defined" > > while

Re: How do you do arrays

2005-02-01 Thread Kartic
and it is called a "List" in Python parlance. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do you do arrays

2005-02-01 Thread Kartic
Tom, Before you use iMatrix[index], you have to tell python to use iMatrix as an array. You will do that using iMatrix = [] *outside* the loop. iMatrix = [] while index < majorlop1: # rest of the loop statements Since you are new, please take a look at the Python tutorial to get you started. htt

How do you do arrays

2005-02-01 Thread Thomas Bunce
I am new at Pyton and I am learning from book not classes so please forgive my being slow The below does not work I get an Error of File "Matrix[index] = k NameError: name 'iMatrix' is not defined" while index < majorlop1: index = index + 1 k = random.choice(listvalues) + 1 iMatrix[in