Python throws valueerror: setting an array element with a sequence, when you are trying to create an array with the list which is not proper multi-dimensional in shape. Another reason is related to the type of content in array. For example, you are defining a float array and inserting string values in it.
Consider this code example –
import numpy as np
print(np.array([[1, 2], [3, 4, 5]]))
PythonCopy
This will throw valueerror setting array element with sequence, because we are asking numpy
to create an array from the list which has elements of different dimensions – [1,2]
and [3,4,5]
.
#python #python error #python numpy #python-short