2

I have a list, which consist collection of differently shaped 2 dimensional numpy arrays inside it. It looks like this.

enter image description here

My goal is to convert this to a 3d numpy array so that its structure is something like this

[ 
  [[ ]
   [ ]
    :
     ],

  [[ ]
   [ ]
    :
     ],

    :
]

or in words

[

 two dimensional array 1,
 two dimensional array 2,
 two dimensional array 3,
       :
       :
]

I tried doing

arr = np.array(garbage)

that gives me an array but it is not structured as I described it. Its shape comes out to be (40336,)

I have to pass the array to a RNN. Do I have to pad zeros for all internal 2 dimensional arrays so that they are of same shape which will make the outer array of the three dimensional shape that I want?

Imanpal Singh
  • 1,105
  • 1
  • 12
  • 22
  • try appending all smaller lists in to a list and then apply np.array on that list – Sabito stands with Ukraine May 22 '20 at 12:01
  • The individual list ( if you are referring to inner two dimensional arrays) are distinct observations. I need them to be as a separate observation so, cannot append them – Imanpal Singh May 22 '20 at 12:04
  • 1
    See https://stackoverflow.com/questions/10346336/list-of-lists-into-numpy-array –  May 22 '20 at 12:05
  • 1
    It won't be really 3 dimensional unless the arrays are even. You may get an array of dtype 'object' with uneven arrays inside. So yeah, padding is definitely necessary particularly for RNNs. – Mercury May 22 '20 at 12:23
  • if anyone has this problem in future refer [here](https://datascience.stackexchange.com/questions/48796/how-to-feed-lstm-with-different-input-array-sizes) for the solution to this problem – Imanpal Singh May 22 '20 at 13:30

0 Answers0