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 Review Multidimensional Arrays

Flore W
Flore W
4,744 Points

Quiz question on rank of matrix

The quiz asks what the rank of the below matrix is:

ratings = np.array([
    [5, 4, 5, 5, 2],
    [5, 5, 5, 5, 4],
    [1, 2, 1, 1, 1]
])

The response is 2 - I agree that the dimension of the matrix is 2, but the rank is different from its dimension.

Wikipedia defines rank as the number of columns that are linearly independent. In which case it would be 3 for this matrix. Is there a different definition in coding?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Good question! Rank is such an overused term, it's easy to mix up the overlapping definitions.

On Wikipedia, the is also Rank (computer programming) which says "In computer programming, rank with no further specifications is usually a synonym for (or refers to) "number of dimensions"; thus, a two-dimensional array has rank two, a three-dimensional array has rank three and so on."

In older versions of NumPy, the was a rank() function, where "rank" used to mean the number of linearly independent rows (that is, it's dimensions). A matrix is 2-dimensional, and would have a "rank" of 2.

In NumPy 1.9.0, the rank() function was deprecated and is not longer used. np.ndim() is now the suggested way to get the dimension of an array.

Post back if you have more questions. Good Luck!!

Flore W
Flore W
4,744 Points

thanks Chris! all clear now :)