我试图将一个numpy矩阵传递给一个对象方法,但我一直得到TypeError:test_obj()只取一个参数(给定2个)
我认为矩阵对象没有被正确解释为矩阵对象,但是当相同的代码作为简单函数运行时,它工作正常.如何使我的对象方法像简单函数一样工作?
码:
from numpy import *
class Tester(object):
def test_obj(x):
print 'test obj:', type(x)
def test_fun(x):
print 'test fun:', type(x)
X = matrix('5.0 7.0')
test_fun(X)
tester = Tester()
tester.test_obj(X)
Run Code Online (Sandbox Code Playgroud)
输出:
test fun: <class 'numpy.matrixlib.defmatrix.matrix'>
Traceback (most recent call last):
File "/home/fornarim/test_matrix.py", line 22, in <module>
tester.test_obj(X)
TypeError: test_obj() takes exactly 1 argument (2 given)
Run Code Online (Sandbox Code Playgroud) 我试图描述一个用Java编写的ann算法,它被实现为一个通用的抽象类,我无法弄清楚如何实例化它.
Eclipse给出了错误"无法实例化KdTree类型"这对我没有帮助.关于如何实例化这个类的任何想法,以便我可以测试它?
类定义和构造函数:
public abstract class KdTree<T> {
private KdTree(int dimensions, Integer sizeLimit) {
this.dimensions = dimensions;
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试实例:
public class test_robo {
public void run_test()
{
KdTree<Integer> tree = new KdTree<Integer>(1,1);
}
}
Run Code Online (Sandbox Code Playgroud)
链接到KdTree的完整代码 http://robowiki.net/wiki/User:Rednaxela/kD-Tree