首页 > 其他分享 >pytorch_geometric的Planetoid出现“TypeError: expected np.ndarray (got matrix)”的问题和解决方法

pytorch_geometric的Planetoid出现“TypeError: expected np.ndarray (got matrix)”的问题和解决方法

时间:2024-08-11 22:29:30浏览次数:13  
标签:TypeError matrix Planetoid torch np got geometric out

问题和解决方案

  • 运行GCN的例子的时候,出现了这个错误:

    out = torch.from_numpy(out).to(torch.float)
    TypeError: expected np.ndarray (got matrix)
    
  • 解决方案:

    1. torch_geometric.io.planetoid.py 中添加 import numpy as np,

    2. out = torch.from_numpy(out).to(torch.float)
      替换成:
      out = torch.as_tensor(np.array(out).astype('float'))
  • 搞定。(可能是版本的问题)

参考

标签:TypeError,matrix,Planetoid,torch,np,got,geometric,out
From: https://www.cnblogs.com/pengpanda/p/18353999

相关文章

  • TypeError: ‘list’ object is not callable 深度解析
    TypeError:‘list’objectisnotcallable深度解析概述:在Python编程中,遇到“TypeError:‘list’objectisnotcallable”这一错误通常意味着你尝试以函数或方法的方式调用了一个列表对象。这种错误往往是由于编码疏忽或理解偏差导致的。本文将深度解析这一......
  • RF运行for循环报错 TypeError: argument of type ‘int‘ is not iterable
    最近写自动化脚本用到了FOR循环,我这里的想用数字迭代去删除ACL条目,上百条要删除,要想解放双手,还的是FOR循环。 但是呢,运行过程中到第一次点击禁用就提示我TypeError:argumentoftype'int'isnotiterable,直接语法错误。这句话是说:整数类型不可迭代,上网搜索好多方法都不......
  • 为什么 xgboost.QuantileDMatrix 使用自定义数据迭代器对数据进行四次传递?
    我正在尝试使用自定义数据迭代器,如下所示此处,因为我的数据集太大。只是为了测试它是如何工作的,我正在使用示例的子集并运行以下代码。X是我的数据的numpy数组。我的迭代器如下所示classIterForQDMatrix(xgb.core.DataIter):def__init__(self,d......
  • TypeError: ‘float’ object is not iterable 深度解析
    TypeError:‘float’objectisnotiterable深度解析与实战指南在Python编程中,TypeError:'float'objectisnotiterable是一个常见的错误,通常发生在尝试对浮点数(float)进行迭代操作时。这个错误表明代码中存在类型使用不当的问题,因为浮点数不是可迭代对象。本文将深入......
  • TypeError: ‘dict’ object is not callable 深度解析
    TypeError:‘dict’objectisnotcallable深度解析在Python编程中,TypeError:'dict'objectisnotcallable是一个常见的错误,通常发生在尝试调用一个字典对象时。这个错误表明代码中存在逻辑错误,可能是将字典误用为函数或方法。本文将深入探讨这一错误的常见原因,并提......
  • LeetCode | 59 SpiralMatrixII
    主类https://github.com/dolphinmind/datastructure/tree/datastructure-array-02循环不变量原则,保证问题边界的逻辑一致性(从二分法的启发)初始位置旋转圈数奇偶性四条边的边界逻辑offsetpackagecom.github.dolphinmind.array;/***@authordolphinmind*@C......
  • 【完美解决】 TypeError: ‘str’ object does not support item assignment
    【完美解决】TypeError:‘str’objectdoesnotsupportitemassignment在Python编程中,遇到TypeError:'str'objectdoesnotsupportitemassignment这样的错误通常意味着你试图修改字符串中的某个字符,但字符串是不可变类型,不支持这种操作。本文将深入探讨这一错误......
  • TypeError:ufunc 的循环不支持 dict 类型的参数 0,该类型没有可调用的 sqrt 方法
    我遇到了一个错误:psi_out_norm.append(np.sqrt(sorted_probs))TypeError:loopofufuncdoesnotsupportargument0oftypedictwhichhasnocallablesqrtmethod不知道如何解决此错误。下面是我正在处理的代码:num_qubits=2sorted_probs={'00':0.182613164......
  • STAT3006/7305 STAT3006/7305  covariance matrix
    STAT3006/7305Tutorial 11. Assumeis bivariate normal with meanand covariance matrixDeriveanexpressionforthemarginaldistributionofX1 .2. Forthe aboveproblem, derive anexpressionfor the conditional distribution of X1 fromthe......
  • 【已解决】TypeError: argument of type ‘int’ is not iterable
    【已解决】TypeError:argumentoftype‘int’isnotiterable在Python编程中,TypeError:argumentoftype'int'isnotiterable是一个常见的错误。此错误表明你尝试对一个整数(int)执行迭代操作,但整数是不可迭代的。本文将深入探讨此错误的根源、解决思路、具体解......