Find length of 2D array Python

arrays, python

Solution

Like this:

numrows = len(input)    # 3 rows in your example
numcols = len(input[0]) # 2 columns in your example

Assuming that all the sublists have the same length (that is, it's not a jagged array).

Problem

How do I find how many rows and columns are in a 2d array? For example, ``` Input = ([[1, 2], [3, 4], [5, 6]])` ``` should be displayed as 3 rows and 2 columns.

Original source