Open dingqunfei opened 6 years ago
one walk around is to replace that line by:
if not isinstance(s_prev,list): s_prev = np.zeros_like(self.state.s)
and the following line:
if not isinstance(h_prev,list): h_prev = np.zeros_like(self.state.h)
This also happens to my Spyder 3.1.2 with Python 2.7.13 64bit.
this change gets to work to me, @zhyma , thanks.
but i'd like to know how not isinstance(s_prev, list)
is equal to s_prev == None
?
because, i'm debugging the code here, and the expected class to s_prev
is numpy.ndarray
, so both values, this array and None will be evaluate as False
in isinstance(s_prev, list)
@tldrafael You are correct. I just got it wrong. With "if not isinstance(s_prev,list)", it runs into resetting s_prev as a zeros_like matrix everytime. Although it is running, the 'H' cell and the 'C' cell are not working properly. Thanks for pointing that out!
The problem seems that you can't compare an array to a single None. To solve that i compare the class of the object to Nonetype if s_prev.__class__ == 'NoneType'
, but after this the script raises another error ValueError: shapes (100,150) and (51,) not aligned: 150 (dim 1) != 51 (dim 0)
. I'm struggling here.
I think using "==" to compare different types is an out-of-date method. I remember it was running correctly on my other machine with an old version of Python but not the up-to-date one. Haven't checked the Python manual yet.
when run test.py, there is a error. ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() changing the '==' of two lines to 'is' is right, it likes 'if s_prev is None: s_prev = np.zeros_like(self.state.s)'