It expects whatever you give it to evaluate to a single number, if it doesn't, Numpy responds that it doesn't know how to set an array element with a sequence. X = np.array() #Fail, can't convert the numpy array to fitĪ numpy array is being created, and numpy doesn't know how to cram multivalued tuples or arrays into single element slots. By trying to cram a numpy array length > 1 into a numpy array element: x = np.array() Numpy.array() #Fail, can't convert a list into a numpyĢ. an() #Fail, can't convert a tuple into a numpy Numpy.array() #Fail, can't convert a tuple into a numpy When you pass a python tuple or list to be interpreted as a numpy array element: import numpy It can be thrown under various circumstances.ġ. Means exactly what it says, you're trying to cram a sequence of numbers into a single number slot.
Without knowing what your code is supposed to accomplish, I can't tell if this is what you want.The Python ValueError: ValueError: setting an array element with a sequence. If you really want to have a NumPy array containing both strings and floats, you could use the dtype object, which enables the array to hold arbitrary Python objects: That is what you are trying according to your edit. So probably UnFilteredDuringExSummaryOfMeansArray contains sequences of different lengths.Īnother possible cause for this error message is trying to use a string as an element in an array of type float: Will yield this error message, because the shape of the input list isn't a (generalised) "box" that can be turned into a multidimensional array. So you can see that I need to specify the data type in order to be able to use ylim in matplotlib, but yet specifying the data type is throwing the error message that initiated this post.įrom the code you showed us, the only thing we can tell is that you are trying to create an array from a list that isn't shaped like a multi-dimensional array. TypeError: cannot perform reduce with flexible type P.ylim(.5*RRDuringArray.min(),1.5*RRDuringArray.max())įile "mypath\mypythonscript.py", line 3631, in CreateSummaryGraphics Then that section of the script works fine without throwing an error, but then this line of code further down the line: RRDuringArray = p.array(UnFilteredDuringExSummaryOfMeansArray) Any other ideas?įYI, if I replace this problem line of code: So I do not think that your idea explains the problem that is happening here. With this same data that I am adding in this.ĮDIT 2: However, the script is throwing an error. Looks like a 5 row by 13 column matrix to me, though the number of rows is variable when different data are run through the script. UnFilteredDuringExSummaryOfMeansArray is: I did a print command to get the contents of the matrix, and this is what it printed out:
ValueError: setting an array element with a sequence.Ĭan anyone show me what to do to fix the problem in the broken code above so that it stops throwing an error message?
RRDuringArray = p.array(UnFilteredDuringExSummaryOfMeansArray,dtype=p.float64)įile "mypath\mypythonscript.py", line 3484, in secondfunction
Secondfunction(UnFilteredDuringExSummaryOfMeansArray)ĭef secondfunction(UnFilteredDuringExSummaryOfMeansArray): UnFilteredDuringExSummaryOfMeansArray.append(conditionMeansArray) MyMeans, myMeans, myMeans, myMeans, myMeans, MyMeans = p.mean(trimmedMatrix,axis=0,dtype=p.float64)ĬonditionMeansArray =, myMeans, TrimmedMatrix = p.array(roughTrimmedMatrix,dtype=p.float64) #ERROR THROWN HERE If you look at the example, the numpy array is 2-dimensional, but at the later stage, we have mixed with single-dimensional array also, and hence Python detects this as an inhomogeneous shape that means the structure of the array. In this case, if the Numpy array is not in the sequence, you will get a Value Error. 'StrokeVolumeMean','CardiacOutputMean','VelocityIndexMean']ĭataMatrix = BeatByBeatMatrixOfMatrices What is valueerror: setting an array element with a sequence A ValueError occurs when a function receives an argument of the correct type, but the value of the type is invalid. 'dZdtMaxVoltageMean','BZMean','ZXMean','LVETMean','Z0Mean', MeanOutputHeader=['TestID','ConditionName','FilterType','RRMean','HRMean',