Ronaldinho Learn Coding Ronaldinho Learn Coding - 1 year ago 123
Python Question

Find length of 2D array Python

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.

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download