Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.