def _pairwise_similarity(a, b, similarity):
 (a_rows, a_cols, b_rows, b_cols) = _check_rows_and_columns(a, b)
 n_a = a_rows.shape[0]
 n_b = b_rows.shape[0]
 result = np.array(list((list((similarity(a_rows[i], a_cols[i], b_rows[j], b_cols[j]) for j in range(n_b))) for i in range(n_a))))
 return result

def _pairwise_similarity ( a , b , similarity ) : ( a_rows , a_cols , b_rows , b_cols ) = _check_rows_and_columns ( a , b ) n_a = a_rows . shape [ 0 ] n_b = b_rows . shape [ 0 ] result = np . array ( list ( ( list ( ( similarity ( a_rows [ i ] , a_cols [ i ] , b_rows [ j ] , b_cols [ j ] ) for j in range ( n_b ) ) ) for i in range ( n_a ) ) ) ) return result
computes pairwise similarity matrix .