此Python代码:
import numpy as p
def firstfunction():
UnFilteredDuringExSummaryOfMeansArray = []
MeanOutputHeader=['TestID','ConditionName','FilterType','RRMean','HRMean',
'dZdtMaxVoltageMean','BZMean','ZXMean','LVETMean','Z0Mean',
'StrokeVolumeMean','CardiacOutputMean','VelocityIndexMean']
dataMatrix = BeatByBeatMatrixOfMatrices[column]
roughTrimmedMatrix = p.array(dataMatrix[1:,1:17])
trimmedMatrix = p.array(roughTrimmedMatrix,dtype=p.float64) #ERROR THROWN HERE
myMeans = p.mean(trimmedMatrix,axis=0,dtype=p.float64)
conditionMeansArray = [TestID,testCondition,'UnfilteredBefore',myMeans[3], myMeans[4],
myMeans[6], myMeans[9], myMeans[10], myMeans[11], myMeans[12],
myMeans[13], myMeans[14], myMeans[15]]
UnFilteredDuringExSummaryOfMeansArray.append(conditionMeansArray)
secondfunction(UnFilteredDuringExSummaryOfMeansArray)
return
def secondfunction(UnFilteredDuringExSummaryOfMeansArray):
RRDuringArray = p.array(UnFilteredDuringExSummaryOfMeansArray,dtype=p.float64)[1:,3]
return
firstfunction()
引发此错误消息:
File "mypath\mypythonscript.py", line 3484, in secondfunction
RRDuringArray = p.array(UnFilteredDuringExSummaryOfMeansArray,dtype=p.float64)[1:,3]
ValueError: setting an array element with a sequence.
谁能告诉我该怎么做才能解决上面破碎的代码中的问题,以便停止抛出错误消息?
编辑: 我做了一个打印命令来获取矩阵的内容,这就是它打印出来的内容:
UnFilteredDuringExSummaryOfMeansArray为:
[['TestID', 'ConditionName', 'FilterType', 'RRMean', 'HRMean', 'dZdtMaxVoltageMean', 'BZMean', 'ZXMean', 'LVETMean', 'Z0Mean', 'StrokeVolumeMean', 'CardiacOutputMean', 'VelocityIndexMean'],
[u'HF101710', 'PreEx10SecondsBEFORE', 'UnfilteredBefore', 0.90670000000000006, 66.257731979420001, 1.8305673000000002, 0.11750000000000001, 0.15120546389880002, 0.26870546389879996, 27.628261216480002, 86.944190346160013, 5.767261352345999, 0.066259118585869997],
[u'HF101710', '25W10SecondsBEFORE', 'UnfilteredBefore', 0.68478571428571422, 87.727887206978565, 2.2965444125714285, 0.099642857142857144, 0.14952476549885715, 0.24916762264164286, 27.010483303721429, 103.5237336525, 9.0682762747642869, 0.085022572648242867],
[u'HF101710', '50W10SecondsBEFORE', 'UnfilteredBefore', 0.54188235294117659, 110.74841107829413, 2.6719262705882354, 0.077705882352917643, 0.15051306356552943, 0.2282189459185294, 26.768787504858825, 111.22827075238826, 12.329456404418824, 0.099814258468417641],
[u'HF101710', '75W10SecondsBEFORE', 'UnfilteredBefore', 0.4561904761904762, 131.52996981880955, 3.1818159523809522, 0.074714285714290493, 0.13459344175047619, 0.20930772746485715, 26.391156337028569, 123.27387909873812, 16.214243779323812, 0.1205685359981619]]
对我来说,这看起来像是5行乘13列的矩阵,但是当通过脚本运行不同的数据时,行数是可变的。使用我要添加的相同数据。
编辑2:但是,脚本抛出错误。因此,我认为您的想法不能解释此处正在发生的问题。谢谢你 还有其他想法吗?
编辑3:
仅供参考,如果我替换此有问题的代码行:
RRDuringArray = p.array(UnFilteredDuringExSummaryOfMeansArray,dtype=p.float64)[1:,3]
与此相反:
RRDuringArray = p.array(UnFilteredDuringExSummaryOfMeansArray)[1:,3]
然后,脚本的该部分可以正常工作而不会引发错误,但是此代码行更进一步:
p.ylim(.5*RRDuringArray.min(),1.5*RRDuringArray.max())
引发此错误:
File "mypath\mypythonscript.py", line 3631, in CreateSummaryGraphics
p.ylim(.5*RRDuringArray.min(),1.5*RRDuringArray.max())
TypeError: cannot perform reduce with flexible type
因此,您可以看到我需要指定数据类型以便能够在matplotlib中使用ylim,但是指定数据类型会引发引发此帖子的错误消息。