W3docs

ValueError: setting an array element with a sequence

This code creates a 2D numpy array, and then tries to set the first element of the array to a list.

Inserting elements of different types in numpy arrays and facing an error in Python

python— editable, runs on the server
Info

Watch a video course: Python - The Practical Guide

This code creates a 2D numpy array, and then tries to set the first element of the array to a list. However, numpy arrays must contain elements of the same data type, so this operation raises a ValueError with the message "setting an array element with a sequence."