Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introduction to NumPy Meet NumPy Multidimensional Arrays

Can someone please help?:)Not sure why I keep getting an error! :(

student_gpas = np.array([[4.01, 3.286, 3.5], [3.2, 3.8, 4.0, 4.0], [3.96, 3.92, 4.0, 4.0]], np.float16) student_gpas


ValueError Traceback (most recent call last) <ipython-input-76-ee784e6a4479> in <module>() ----> 1 student_gpas = np.array([[4.01, 3.286, 3.5], [3.2, 3.8, 4.0, 4.0], [3.96, 3.92, 4.0, 4.0]], np.float16) 2 student_gpas

ValueError: setting an array element with a sequence.

1 Answer

Hi Kafe,

It seems your first list "[4.01, 3.285, 3.5]" element in the np.array only has 3 items (grades) while the others both have four. If you add another grade to make this a 3x4 dimensional matrix it works. If you don't have a grade to add, you can still make this work by simply putting 'nan' in place of the missing grade(s). Note: 'nan' is recognized by Python as "not a number" and is used to fill in missing data. It may look like a string (need to use quotes for this list item), but any string or an empty string doesn't work and results in a datatype incompatibility with your float16 type.