{"id":265,"hash":"81801fdcdf299cfe69062442b7173a2c30cea5dfc2472708b0634f1c952c3db8","pattern":"ValueError: setting an array element with a sequence","full_message":"Why do the following code samples:\n\nnp.array([[1, 2], [2, 3, 4]])\n\nnp.array([1.2, \"abc\"], dtype=float)\n\nall give the following error?\n\nValueError: setting an array element with a sequence.","ecosystem":"pypi","package_name":"arrays","package_version":null,"solution":"Possible reason 1: trying to create a jagged array\nYou may be creating an array from a list that isn't shaped like a multi-dimensional array:\n\nnumpy.array([[1, 2], [2, 3, 4]])         # wrong!\n\nnumpy.array([[1, 2], [2, [3, 4]]])       # wrong!\n\nIn these examples, the argument to numpy.array contains sequences of different lengths. Those will yield this error message because the input list is not shaped like a \"box\" that can be turned into a multidimensional array.\n\nPossible reason 2: providing elements of incompatible types\nFor example, providing a string as an element in an array of type float:\n\nnumpy.array([1.2, \"abc\"], dtype=float)   # wrong!\n\nIf you really want to have a NumPy array containing both strings and floats, you could use the dtype object, which allows the array to hold arbitrary Python objects:\n\nnumpy.array([1.2, \"abc\"], dtype=object)","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/4674473/valueerror-setting-an-array-element-with-a-sequence","votes":340,"created_at":"2026-04-19T04:41:42.948969+00:00","updated_at":"2026-04-19T04:51:54.603401+00:00"}