build matrix from arr