Combine list of numpy arrays and reshape
<p>I'm hoping anybody could help me with the following.
I have 2 lists of arrays, which should be linked to each-other. Each list stands for a certain object. <code>arr1</code> and <code>arr2</code> are the attributes of that object. 
For example:</p>

<pre><code>import numpy as np

arr1 = [np.array([1, 2, 3]), np.array([1, 2]), np.array([2, 3])]
arr2 = [np.array([20, 50, 30]), np.array([50, 50]), np.array([75, 25])]
</code></pre>

<p>The arrays are linked to each other as in the <code>1</code> in <code>arr1</code>, first array belongs to the <code>20</code> in <code>arr2</code> first array. The result I'm looking for in this example would be a numpy array with size 3,4. The 'columns' stand for 0, 1, 2, 3 (the numbers in arr1, plus 0) and the rows are filled with the corresponding values of arr2. When there are no corresponding values this cell should be 0. 
Example:</p>

<pre><code>array([[ 0, 20, 50, 30],
       [ 0, 50, 50,  0],
       [ 0,  0, 75, 25]])
</code></pre>

<p>How would I link these two list of arrays and reshape them in the desired format as shown in the above example?</p>

<p>Many thanks!</p>

<p>Here is a solution with for-loops. Showing each step in detail.</p>

<pre><code>import numpy as np

arr1 = [np.array([1, 2, 3]), np.array([1, 2]), np.array([2, 3])]
arr2 = [np.array([20, 50, 30]), np.array([50, 50]), np.array([75, 25])]

maxi = []
for i in range(len(arr1)):
    maxi.append(np.max(arr1[i]))
maxi = np.max(maxi)
output = np.zeros((len(arr2),maxi))
for i in range(len(arr1)):
    for k in range(len(arr1[i])):
        output[i][k]=arr2[i][k]
</code></pre>

python arrays numpy