使用tensorflow进行umapfit_transforminputs出现TypeError __array__ takes 1 positional argument but 2 were given inputseval转换为numpy数组时出现ValueError Cannot evaluate tensor using eval 使用的是tensorflow—gpu 115版本
这个问题可能是因为您正在使用TensorFlow的Eager Execution模式,而不是Graph Execution模式。在Eager Execution模式下,您不能使用eval()方法来评估TensorFlow张量。
如果您想使用umap库进行降维,可以使用以下方法:
- 将TensorFlow张量转换为NumPy数组,然后传递给
umap.fit_transform()方法。例如:
import tensorflow as tf
import umap
# 创建一个TensorFlow张量
inputs = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
# 将TensorFlow张量转换为NumPy数组
inputs_np = inputs.numpy()
# 使用umap进行降维
umap_result = umap.fit_transform(inputs_np)
- 使用
tf.Session()来运行图并获取张量的值,然后将其转换为NumPy数组。例如:
import tensorflow as tf
import umap
# 创建一个TensorFlow张量
inputs = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
# 创建一个Session对象
with tf.Session() as sess:
# 运行图并获取张量的值
inputs_val = sess.run(inputs)
# 将TensorFlow张量转换为NumPy数组
inputs_np = inputs_val.numpy()
# 使用umap进行降维
umap_result = umap.fit_transform(inputs_np)
请注意,第二种方法需要在with tf.Session() as sess:块中运行图,并且需要在每个张量上调用sess.run()来获取它的值。
原文地址: https://www.cveoy.top/t/topic/bJmO 著作权归作者所有。请勿转载和采集!