аватар question@mail.ru · 01.01.1970 03:00

Creation of a N-dimensional array of length n

Can I create N -dimensional array? If so, how to realize it? If the matrix is ​​a “list of lists”, then it will look something like this:

  [[...]], [[...] ...]]     

, or so that it is more clear, like it is more clear, like it is more clear. n of the invested segments, the picture below,

  (A1 [...] ...] B1, a2_m [...] ...] b2_m, ...)     

and how to realize it in the code? If we say, I need to introduce n from the keyboard. Thank you very much!

аватар answer@mail.ru · 01.01.1970 03:00

I tried to use the recursion. The first argument is the depth of the array. The second argument is the number of elements in the massif.

   def   quant_array  ( n, x ):   try :   assert   isinstance  (n,  int )   except  assertionerror:   retu   "" Input an integer! "   if  n & lt; =  1 :   retu *x  retu  [(n, quant_array (n-  1 , x)]*x  print  (quant_array ( 3 ,  2 ))     

[(3, [2, [1, 1]), (2, [1, 1])]), (3, [(2, [1, 1]), (2, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, [1, SHADOM 1])])]

Latest

Similar