ValueError: setting an array element with a sequence

后端 未结 8 1186
萌比男神i
萌比男神i 2020-11-22 05:46

This Python code:

import numpy as p

def firstfunction():
    UnFilteredDuringExSummaryOfMeansArray = []
    MeanOutputHeader=[\'TestID\',\'         


        
8条回答
  •  旧时难觅i
    2020-11-22 06:40

    From 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. For example

    numpy.array([[1,2], [2, 3, 4]])
    

    or

    numpy.array([[1,2], [2, [3, 4]]])
    

    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 probably UnFilteredDuringExSummaryOfMeansArray contains sequences of different lengths.

    Edit: Another possible cause for this error message is trying to use a string as an element in an array of type float:

    numpy.array([1.2, "abc"], dtype=float)
    

    That is what you are trying according to your edit. 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([1.2, "abc"], dtype=object)
    

    Without knowing what your code shall accomplish, I can't judge if this is what you want.

提交回复
热议问题