Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

line 85&86:if s_prev == None: s_prev = np.zeros_like(self.state.s) #28

Open
dingqunfei opened this issue Aug 16, 2017 · 5 comments
Open

Comments

@dingqunfei
Copy link

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)'

@zhyma
Copy link

zhyma commented Aug 22, 2017

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.

@tldrafael
Copy link

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)

@zhyma
Copy link

zhyma commented Sep 26, 2017

@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!

@tldrafael
Copy link

tldrafael commented Sep 26, 2017

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.

@zhyma
Copy link

zhyma commented Sep 26, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants