这两个错误是由于您正在使用PyTorch的张量(Tensor)而不是NumPy数组。如果您想使用umap.fit_transform()函数,您需要将PyTorch张量转换为NumPy数组。您可以使用以下代码将PyTorch张量转换为NumPy数组:

import numpy as np
inputs_np = inputs.detach().numpy()

然后,您可以使用以下代码将NumPy数组传递给umap.fit_transform()函数:

import umap
umap_emb = umap.UMAP(n_neighbors=10, min_dist=0.1, metric='cosine').fit_transform(inputs_np)

请注意,您需要使用.detach()函数从PyTorch张量中分离数据,以便在不影响梯度计算的情况下将其转换为NumPy数组。

umapfit_transforminputs出现TypeError __array__ takes 1 positional argument but 2 were given inputsnumpy转换为numpy数组时出现AttributeError Tensor object has no attribute numpy

原文地址: https://www.cveoy.top/t/topic/bJkW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录