简体   繁体   English

TypeError: 'numpy.ndarray' 对象不可调用,用于比较两行

[英]TypeError: 'numpy.ndarray' object is not callable, for comparing two lines

I tried to compare two plotted lines.我试图比较两条绘制的线。 I first load two data files and assign the x and y, and then tried to even the points on the x axes.我首先加载两个数据文件并分配 x 和 y,然后尝试平衡 x 轴上的点。 However, an error popped out:但是,弹出一个错误:

Traceback (most recent call last): File "/Users/renzha/Documents/compare two lines.py", line 33, in xnew = data1[:,0] ( min(x), max(x), num = points) TypeError: 'numpy.ndarray' object is not callable回溯(最近一次调用最后一次):文件“/Users/renzha/Documents/compare two lines.py”,第33行,在xnew = data1[:,0] ( min(x), max(x), num = points) TypeError: 'numpy.ndarray' 对象不可调用

Original code is:原代码为:

import numpy as np
from scipy.interpolate import interp1d
import matplotlib.pyplot as plt
import scipy.spatial.distance as ssd 
import scipy.stats as ss
data1 = np.loadtxt(filedialog.askopenfilename(), delimiter='\t')
data2 = np.loadtxt(filedialog.askopenfilename(), delimiter='\t')
x = data1[:,0]
y = data1[:,1]
x2 = data2[:,0]
y2 = data2[:,1]
f = interp1d(x, y)
f2 = interp1d(x2,y2)
points = 150
xnew = data1[:,0] ( min(x), max(x), num = points) 
xnew2 = data2[:,0] ( min(x2), max(x2), num = points) 
ynew = f(xnew) 
ynew2 = f2(xnew2) 
plt.plot(x,y, 'r', x2, y2, 'g', xnew, ynew, 'r--', xnew2, ynew2, 'g--')
plt.show()
print (ssd.correlation(ynew, ynew2))
print (np.correlate(ynew, ynew2, mode='valid'))
print (np.corrcoef(ynew, ynew2)) 
print (ss.spearmanr(ynew, ynew2)) 

As the errors said, your data data1[:,0] and data2[:,0] are numpy arrays.正如错误所说,您的数据data1[:,0]data2[:,0]是 numpy 数组。 I guess you are trying to apply a function with parameters ( min(x), max(x), num = points) , check again the code to see which function should be used there.我猜你正在尝试应用一个带参数的函数( min(x), max(x), num = points) ,再次检查代码以查看应该在那里使用哪个函数。 Looking at the name of the parameters, maybe numpy.linspace(start, stop, num= ...) could help.查看参数的名称,也许numpy.linspace(start, stop, num= ...)会有所帮助。

https://numpy.org/doc/stable/reference/generated/numpy.linspace.html#numpy.linspace https://numpy.org/doc/stable/reference/generated/numpy.linspace.html#numpy.linspace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到TypeError:'numpy.ndarray'对象不可调用 - getting TypeError: 'numpy.ndarray' object is not callable Pyomo,TypeError:'numpy.ndarray' 对象不可调用 - Pyomo, TypeError: 'numpy.ndarray' object is not callable 多重处理:TypeError:“ numpy.ndarray”对象不可调用 - multiprocessing: TypeError: 'numpy.ndarray' object is not callable 未知的TypeError:'numpy.ndarray'对象不可调用 - Uknown TypeError: 'numpy.ndarray' object is not callable “类型错误:'numpy.ndarray' 对象不可调用” - Numpy 错误 - "TypeError: 'numpy.ndarray' object is not callable " - Numpy Error 'numpy.ndarray'对象不可调用 - 'numpy.ndarray' object is not callable “'numpy.ndarray'对象不可调用” - “'numpy.ndarray' object is not callable” 类型错误:'numpy.ndarray' object 不可调用。 奇怪的错误 - TypeError: 'numpy.ndarray' object is not callable. Strange error 如何修复'TypeError:'numpy.ndarray'对象不可调用' - how to fix 'TypeError: 'numpy.ndarray' object is not callable' 类型错误:'numpy.ndarray' 对象在 for 循环 Python 中不可调用 - TypeError: 'numpy.ndarray' object is not callable within for loop Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM