Re: Yet another "simple" headscratcher

2014-06-01 Thread wxjmfauth
>>> # from my lib >>> def NewMat(nr, nc, val=0.0): ... val = float(val) ... return [[val] * nc for i in range(nr)] ... >>> import vmio6 >>> aa = NewMat(2, 3) >>> vmio6.pr(aa) ( 0.0e+000 0.0e+000 0.0e+000 ) ( 0.0e+000 0.0e+000 0.0e+000 ) >>> aa[0][0] = 3.

Re: Yet another "simple" headscratcher

2014-05-30 Thread Ian Kelly
On Fri, May 30, 2014 at 9:38 PM, Josh English wrote: > I am trying to whip up a quick matrix class that can handle multiplication. > > Should be no problem, except when it fails. > > [SNIP] > > def zero_matrix(rows, cols): > row = [0] * cols > data = [] > for r in range(rows): >

Re: Yet another "simple" headscratcher

2014-05-30 Thread Gary Herron
On 05/30/2014 08:38 PM, Josh English wrote: ... def zero_matrix(rows, cols): row = [0] * cols data = [] for r in range(rows): data.append(row) return Matrix(data) There is a simple and common newbie mistake here.It looks like you are appending several copies

Re: Yet another "simple" headscratcher

2014-05-30 Thread Josh English
Mea culpa, gang. I found it. It had absolutely nothing to do with the multiplication. It was in zero_matrix. I feel like a fool. Josh -- https://mail.python.org/mailman/listinfo/python-list

Yet another "simple" headscratcher

2014-05-30 Thread Josh English
I am trying to whip up a quick matrix class that can handle multiplication. Should be no problem, except when it fails. --- Begin #!/usr/bin/env python # _*_ coding: utf-8 from operator import mul class Matrix(object): """Matrix([data]) Data should be a list of equal sized lists. De