>>> # 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.
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):
>
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
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
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