

python – ValueError: setting an array element with a sequence
#SETTING AN ARRAY ELEMENT WITH A SEQUENCE. HOW TO#
It expects whatever you give it to evaluate to a single number, if it doesnt, Numpy responds that it doesnt know how to set an array element with a sequence. X = np.array() #Fail, cant convert the numpy array to fitĪ numpy array is being created, and numpy doesnt 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, cant convert a list into a numpyĢ. an() #Fail, cant convert a tuple into a numpy Numpy.array() #Fail, cant 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, youre trying to cram a sequence of numbers into a single number slot. The Python ValueError: ValueError: setting an array element with a sequence. Without knowing what your code is supposed to accomplish, I cant tell if this is what you want. 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: numpy.array(, dtype=object) 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: numpy.array(, dtype=float) # wrong!

Will yield this error message, because the shape of the input list isnt a (generalised) box that can be turned into a multidimensional array. Python – ValueError: setting an array element with a sequenceį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 isnt shaped like a multi-dimensional array.
