查找二维数组 Python 的长度 [英] Find length of 2D array Python
本文介绍了查找二维数组 Python 的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何找到二维数组中有多少行和列?
How do I find how many rows and columns are in a 2d array?
例如
Input = ([[1, 2], [3, 4], [5, 6]])`
应显示为 3 行 2 列.
should be displayed as 3 rows and 2 columns.
推荐答案
像这样:
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).
这篇关于查找二维数组 Python 的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文