count shape of matrix