I would like to use function of same name from different packages dependent on a function flag:
import chainer.functions as F
def random_q_z(input, test = False):
if test:
F = np
# ...
else:
# ...
pass
return F.sum(input)
However the interpreter protests:
UnboundLocalError: local variable 'F' referenced before assignment
How to please it and do conditional referencing of packages?
I see that this question relates to other questions on variable scopes, but here the question is about how to handle different scopes. And the answer I got is valuable for this particular question.