. Advertisement .
..3..
. Advertisement .
..4..
I had used some code samples in another forum, but it could not improve the problem. My problem is the “error: valueerror: setting an array element with a sequence.” and how to solve it? While I run this program:
# In this program we are demonstrating how mismatch
# of data-type can cause value error
import numpy
# Creating array
array1 = ["Geeks", "For"]
# Default Data type of Array
Data_type = str
np_array = numpy.array(array1, dtype=Data_type)
# This cause error
np_array[1] = ["for", "Geeks"]
print(np_array)
I have got this error:
File “C:\\Users\\computers\\Downloads\\he.py”, line 15, in <module>
np_array[1] = [“for”,”Geeks”];
ValueError: setting an array element with a sequence
What does the message mean? Can you advise me to fix it? If you have other better answers, leave them in the answer box below. Thanks!
The cause:
You have got this error because an array as a element is being assigned to another array which accepts string data-type.
Solution:
This error willed be fixed when you matchthe data-type of value with an array and then assign it as element of array.
You can use below syntax to do this:
Your code after fixed will like as: