进入代码森林在线运行Tensorflow2的代码编辑器中,题目:从开始(默认值=0)生成一个数字序列,增量为 delta(默认值=1),直到终值(但不包括终值):
tf.range(start,limit,delta)
实例代码:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
range_t = tf.range(10)
sess=tf.compat.v1.Session()
print(sess.run(range_t))
输出结果:
[0 1 2 3 4 5 6 7 8 9]
生成100以内的能被5整除的数字
实例代码:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
range_t = tf.range(0,100,5)
sess=tf.compat.v1.Session()
print(sess.run(range_t))
输出结果:
[ 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95]