Find the dimensions of a multidimensional Python array

前端 未结 4 1378
小鲜肉
小鲜肉 2021-02-07 05:59

In Python, is it possible to write a function that returns the dimensions of a multidimensional array (given the assumption that the array\'s dimensions are not jagged)?

4条回答
  •  醉话见心
    2021-02-07 06:39

    Assuming the input array is not jagged :

    def arr_dimen(a):
      return [len(a)]+arr_dimen(a[0]) if(type(a) == list) else []
    

提交回复
热议问题