@怎么把tensor转变成numpy
1、由于tensorflow的升级,所以要加上tf.vompat.v1.diable_egger_exectution(),具体代码如下
下面展示一些 内联代码片。
// A code block
a = tf.constant([1,2,3])
tf.compat.v1.diable_eager_exection()
a = tf.compat.v1.Session().run(a)
// An highlighted block
a = tf.constant([1,2,3])
tf.compat.v1.diable_eager_exection()
a = tf.compat.v1.Session().run(a);
这样就弄好了
2、数组(numpy)转化为列表(list)
下面展示一些 内联代码片。
// A code block
a =np.array( [1,2,3])
a = a.tolist()
// An highlighted block
a = np.array([1,2,3])
a = a.tolist()
3、列表(list)转化为数组(numpy)
下面展示一些 内联代码片。
// A code block
a = [1,2,3]
a = np.array([a])
// An highlighted block
a = [1,2,3]
a = np.array([a])
本文介绍了如何在Tensorflow环境中将tensor转换为numpy数组,再将numpy数组转换为列表。首先,由于Tensorflow版本更新,需要使用tf.compat.v1.disable_eager_execution()。接着,展示了具体的转换代码示例,包括tensor转numpy和numpy转list的过程。
,数组(numpy)转化为列表(list),列表(list)转化为数组(numpy)&spm=1001.2101.3001.5002&articleId=116356716&d=1&t=3&u=4ffab03b2f8748c991f3e10490b973e0)
1840

被折叠的 条评论
为什么被折叠?



