When I create Matrix calling g (gclass object)
I get KeyError but calling g directly I do not
Any idea?
class gclass(object):
def __init__(self):
self.components = {}
def __call__(self, *idxs):
if idxs in self.components.keys():
return self.components[idxs]
else:
component = sum(idxs[i] for i in range(len(idxs)))
self.components.update({idxs: component})
return component
g = gclass()
g(1, 1)
print g(1, 1)
Matrix(4,4, lambda i,j: g(i, j))
---------------------------------------------------------------------------KeyError
Traceback (most recent call
last)<ipython-input-50-17a658aa0dab> in <module>() 13 g(1, 1) 14 print
g(1, 1)---> 15 Matrix(4,4, lambda i,j: g(i, j))
/usr/local/lib/python2.7/dist-packages/sympy/matrices/dense.pyc in __new__(cls,
*args, **kwargs) 606 607 def __new__(cls, *args, **kwargs):--> 608
return cls._new(*args, **kwargs) 609 610 def as_mutable(self):
/usr/local/lib/python2.7/dist-packages/sympy/matrices/dense.pyc in _new(cls,
*args, **kwargs) 598 @classmethod 599 def _new(cls, *args,
**kwargs):--> 600 rows, cols, flat_list =
cls._handle_creation_inputs(*args, **kwargs) 601 self =
object.__new__(cls) 602 self.rows = rows
/usr/local/lib/python2.7/dist-packages/sympy/matrices/matrices.pyc in
_handle_creation_inputs(cls, *args, **kwargs) 146 for i in
range(rows): 147
flat_list.extend([cls._sympify(operation(cls._sympify(i), j))--> 148
for j in range(cols)]) 149 150 # Matrix(2, 2, [1, 2, 3,
4])
<ipython-input-50-17a658aa0dab> in <lambda>(i, j) 13 g(1, 1) 14 print
g(1, 1)---> 15 Matrix(4,4, lambda i,j: g(i, j))
<ipython-input-50-17a658aa0dab> in __call__(self, *idxs) 4 def
__call__(self, *idxs): 5 if idxs in self.components.keys():----> 6
return self.components[idxs] 7 else: 8
component = sum(idxs[i] for i in range(len(idxs)))
KeyError: (1, 1)
2
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.