Python 3.x 不断获取错误`TypeError:';浮动';对象不可调用';尝试使用numpy库运行文件时
我打算对从文件中读取的一些数据执行Newton-Raphson迭代。我在python程序中使用以下函数Python 3.x 不断获取错误`TypeError:';浮动';对象不可调用';尝试使用numpy库运行文件时,python-3.x,numpy,Python 3.x,Numpy,我打算对从文件中读取的一些数据执行Newton-Raphson迭代。我在python程序中使用以下函数 def newton_raphson(r1, r2): guess1 = 2 * numpy.log(2) / (numpy.pi() * (r1 + r2)) 我将此函数称为: if answer == "f": # if data is in file fileName = input("What is the name of the file you want to
def newton_raphson(r1, r2):
guess1 = 2 * numpy.log(2) / (numpy.pi() * (r1 + r2))
我将此函数称为:
if answer == "f": # if data is in file
fileName = input("What is the name of the file you want to open?")
dataArray = extract_data_from_file(fileName)
resistivityArray = []
for i in range(0, len(dataArray[0])):
resistivity_point = newton_raphson(dataArray[0][i], dataArray[1][i])
resistivityArray += [resistivity_point]
在运行程序并输入我的文件时,返回'TypeError:'float'对象不可调用'。我在网上读到的所有信息都表明,这是因为我的代码中缺少了一个操作符,但我看不出我在哪里。为什么我总是遇到这个错误?我如何避免它?
numpy.pi
不是一个函数,而是一个常量:
>>> import numpy
>>> numpy.pi
3.141592653589793
从中删除()
调用:
def newton_raphson(r1, r2):
guess1 = 2 * numpy.log(2) / (numpy.pi * (r1 + r2))
因为这会导致您的错误:
>>> numpy.pi()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'float' object is not callable
>>numpy.pi()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:“float”对象不可调用
您似乎正在调用pi
,它是一个常量,而不是一个函数。