Python3 Solution
\n\nclass Solution:\n    def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int:\n        n=len(matrix)\n        m=len(matrix[0])\n       
\n```\nclass Solution:\n    def numSubmatrixSumTarget(self, matrix: List[List[int]], target: int) -> int:\n        n=len(matrix)\n        m=len(matrix[0])\n        ans=0\n        for r in matrix:\n            for i in range(1,len(r)):\n                r[i]+=r[i-1]\n        for start in range(m):\n            for end in range(start,m):\n                lookup=defaultdict(int)\n                cumsum=0\n                lookup[0]=1\n                for k in range(n):\n                    cumsum+=matrix[k][end] - (matrix[k][start-1] if start !=0 else 0)\n                    if cumsum -target in lookup:\n                        ans+=lookup[cumsum-target]\n                    lookup[cumsum]+=1\n        return ans                        \n```
['Python', 'Python3']