How can I find the dimensions of a matrix in Python. Len(A) returns only one variable.
Edit:
close = dataobj.get_data(timestamps, symbols, closefield)
Is (I assume) generating a matrix of integers (less likely strings). I need to find the size of that matrix, so I can run some tests without having to iterate through all of the elements. As far as the data type goes, I assume it's an array of arrays (or list of lists).
The dimensions of a matrix are the number of rows by the number of columns. If a matrix has a rows and b columns, it is an a×b matrix. For example, the first matrix shown below is a 2×2 matrix; the second one is a 1×4 matrix; and the third one is a 3×3 matrix.
The number of rows of a list of lists would be: len(A)
and the number of columns len(A[0])
given that all rows have the same number of columns, i.e. all lists in each index are of the same size.
If you are using NumPy arrays, shape can be used. For example
>>> a = numpy.array([[[1,2,3],[1,2,3]],[[12,3,4],[2,1,3]]]) >>> a array([[[ 1, 2, 3], [ 1, 2, 3]], [[12, 3, 4], [ 2, 1, 3]]]) >>> a.shape (2, 2, 3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With