查找2D数组Python的长度 [英] Find length of 2D array Python

查看:120
本文介绍了查找2D数组Python的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查找2d数组中有多少行和几列?

How do I find how many rows and columns are in a 2d array?

例如,

Input = ([[1, 2], [3, 4], [5, 6]])`

应显示为3行2列.

推荐答案

像这样:

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

这篇关于查找2D数组Python的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆