Search code examples
pythontheano

How to get name of a shared variable in Theano?


How to get name of a shared variable in Theano? I see that printing it or using str() works, but is the correct way to do so? Is there any function similar to X.get_value() (e.g. X.get_name())?

Example:

import theano as th
import numpy as np

X = th.shared(name='xx', value=np.zeros(shape=(2), dtype=th.config.floatX), borrow=True)

print(X)              # print 'xx'
print(str(X) == 'xx') # print 'True'
print(X.get_value())  # print [ 0.  0.]

Solution

  • You get the name of a shared variable x by getting x.name. Unfortunately this is not documented.