def _to_matrix_vectorized(M):
 assert isinstance(M, (tuple, list))
 assert all([isinstance(item, (tuple, list)) for item in M])
 c_vec = np.asarray([len(item) for item in M])
 assert np.all(((c_vec - c_vec[0]) == 0))
 r = len(M)
 c = c_vec[0]
 M00 = np.asarray(M[0][0])
 dt = M00.dtype
 sh = [M00.shape[0], r, c]
 M_ret = np.empty(sh, dtype=dt)
 for irow in range(r):
  for icol in range(c):
   M_ret[:, irow, icol] = np.asarray(M[irow][icol])
 return M_ret

def _to_matrix_vectorized ( M ) : assert isinstance ( M , ( tuple , list ) ) assert all ( [ isinstance ( item , ( tuple , list ) ) for item in M ] ) c_vec = np . asarray ( [ len ( item ) for item in M ] ) assert np . all ( ( ( c_vec - c_vec [ 0 ] ) == 0 ) ) r = len ( M ) c = c_vec [ 0 ] M00 = np . asarray ( M [ 0 ] [ 0 ] ) dt = M00 . dtype sh = [ M00 . shape [ 0 ] , r , c ] M_ret = np . empty ( sh , dtype = dt ) for irow in range ( r ) : for icol in range ( c ) : M_ret [ : , irow , icol ] = np . asarray ( M [ irow ] [ icol ] ) return M_ret
builds an array of matrices from individuals np .