我有此代码:
import time
import tensorflow as tf
input_data = tf.constant([[1.,1.]])
output_data = tf.constant([[1.,0.]])
weight = tf.Variable([[1.,1.],
[1.,1.]])
optimizer = tf.train.GradientDescentOptimizer(0.1)
y = tf.matmul(input_data, weight)
loss = (output_data[0][0] - y[0][0])**2 + (output_data[0][1] - y[0][1])**2
train = optimizer.minimize(loss)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print('Initial weights: ', sess.run(weight))
for epoch in range(1000):
st = time.time()
sess.run(train)
print('Epoch %3d : %.3f ms' %(epoch, 1e3*(time.time()-st)))
print('Weights: ', sess.run(weight))
我想做类似的事情:
class Foo
def run(scope:)
p scope
end
end
module Bar
Foo.run(scope: self) # >> Bar
end
Foo.run(scope: self) # >> main
具有相同的结果。有没有一种方法可以在不显式提及该方法的情况下获得调用方法的module Bar
Foo.run
end
Foo.run
?