Re: Python bug? Indexing to matrices

2011-07-12 Thread David
Thank all for the very helpful replies. The goal of the matrix multiply exercise was just to help my son and I learn Python better. I now understand *why* my initialization of [c] was wrong and I am continuing to check out numpy and scipy. Regards, David -- http://mail.python.org/mailman/listinf

Re: Python bug? Indexing to matrices

2011-07-12 Thread sturlamolden
On 12 Jul, 14:59, sturlamolden wrote: >    ma = np.matrix(a) >    mb = np.matrix(b) >    a*b ma*mb Sorry for the typo. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python bug? Indexing to matrices

2011-07-12 Thread sturlamolden
On 12 Jul, 07:39, David wrote: > Should the following line work for defining a matrix with zeros? > > c= [[0]*col]*row No. The rows will be aliased. This will work: c = [[0]*col for i in range(row)] Note that Python lists are not ment to be used as matrices. We have NumPy or the array module f

Re: Python bug? Indexing to matrices

2011-07-11 Thread Ben Finney
David writes: > Should the following line work for defining a matrix with zeros? > > c= [[0]*col]*row No. Python lists are not matrixes and are not arrays. If you want good implementations of arrays and matrices, use NumPy http://numpy.scipy.org/>. -- \ “Properly read, the Bible is the

Re: Python bug? Indexing to matrices

2011-07-11 Thread Chris Rebert
On Mon, Jul 11, 2011 at 10:39 PM, David wrote: > Should the following line work for defining a matrix with zeros? > > c= [[0]*col]*row > > where "col" is the number of columns in the matrix and "row" is of > course the number of rows. Nope. See the FAQ: http://docs.python.org/faq/programming.html

Python bug? Indexing to matrices

2011-07-11 Thread David
Should the following line work for defining a matrix with zeros? c= [[0]*col]*row where "col" is the number of columns in the matrix and "row" is of course the number of rows. If this a valid way of initializing a matrix in Python 3.2.1, then it appears to me that a bug surfaces in Python when p