【发布时间】:2015-01-02 21:39:18
【问题描述】:
我在尝试运行时遇到问题(在 Python 上):
#Loading in the text file in need of analysis
x,y=loadtxt('2.8k to 293k 15102014_rerun 47_0K.txt',skiprows=1,unpack=True,dtype=float,delimiter=",")
C=-1.0 #Need to flip my voltage axis
yone=C*y #Actually flipping the array
plot(x,yone)#Test
origin=600.0#Where is the origin? i.e V=0, taking the 0 to 1V elements of array
xorg=x[origin:1201]# Array from the origin to the final point (n)
xfit=xorg[(x>0.85)==True] # Taking the array from the origin and shortening it further to get relevant area
它返回 ValueError。我尝试用一个包含 10 个元素的小得多的数组来完成这个过程,xfit=xorg[(x>0.85)==True] 命令工作正常。该程序试图做的是将某些数据的视野缩小到相关点,以便我可以拟合一条最适合数据线性元素的线。
对于格式混乱,我深表歉意,但这是我在此网站上提出的第一个问题,因为我无法搜索我能理解的问题所在。
【问题讨论】:
-
(x>0.85)==True最好写成x>0.85 -
xorg有 600 个元素,x至少有 1200 个元素。当您使用表达式x<0.85索引xorg时,您正在使用一个至少包含 1200 个元素的布尔数组来索引一个 600 个元素的数组。python大声抱怨...
标签: python arrays numpy boolean