p = [[0,0],[0,0],[0,0]].
I know that len(p) returns the width of a list but how do I get the height of a list which is 3 in this case?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no such thing as a “height” of a list. You probably mean “when we choose to represent a matrix as a list-of-lists, what is the height of the matrix”? (sidenote: There are many ways to represent matrices.)
You could take the first row:
but you’d run into an error if you had
[], so what you want is:(Other things to keep in mind: if it’s acceptable to have an Nx0 matrix represented like
[[],[],[],...]. I’d say no. Is[]how you represent empty matrices? I’d say yes. However some libraries likenumpychose differently:numpy.matrix([]).tolist()–>[[]]andnumpy.matrix([[],[],[]])–>matrix([], shape=(3, 0), dtype=float64).)