qiaochen / VeloAE

Low-dimensional Projection of Single Cell Velocity
MIT License
28 stars 1 forks source link

tensor_s, tensor_u, tensor_x = main_AE(args, adata) get error: 'numpy.ndarray' object has no attribute 'toarray' #2

Closed Roger-GOAT closed 2 years ago

Roger-GOAT commented 2 years ago

Hi, the software would be a great improvement on RNA velocyto analysis! THANKS I get an error would you give some tips.

tensor_s, tensor_u, tensor_x = main_AE(args, adata)

AttributeError Traceback (most recent call last) Input In [26], in ----> 1 tensor_s, tensor_u, tensor_x = main_AE(args, adata)

Input In [11], in main_AE(args, adata) 4 tensor_s = torch.FloatTensor(spliced).to(device) 5 tensor_u = torch.FloatTensor(unspliced).to(device) ----> 6 tensor_x = torch.FloatTensor(adata.X.toarray()).to(device) 8 model = init_model(adata, args, device) 10 inputs = [tensor_s, tensor_u]

AttributeError: 'numpy.ndarray' object has no attribute 'toarray'

qiaochen commented 2 years ago

Hi, thank you for your interest in VeloAE! The error is raised because the data type of "adata.X" in your scenario is not sparse matrix, which would have a ".toarray()" function to be converted to dense array.

If adata.X is already a dense array in your code, simply delete ".toarray()" should work: i.e. convert the following line tensor_x = torch.FloatTensor(adata.X.toarray()).to(device) to tensor_x = torch.FloatTensor(adata.X).to(device)

Hope it works!

Roger-GOAT commented 2 years ago

thank you, it has been solved!