class Solution(object):
def matrixReshape(self, nums, r, c):
"""
:type nums: List[List[int]]
:type r: int
:type c: int
:rtype: List[List[int]]
"""
row=len(nums)
colum=len(nums[0])
if row*colum!=r*c:
return nums
else:
tmp=[num for row in nums for num in row]
newarray=[[0 for j in range(c)]for i in range(r)]
for i in range(r):
for j in range(c):
newarray[i][j]=tmp[i*c+j]
return newarray
def matrixReshape(self, nums, r, c):
"""
:type nums: List[List[int]]
:type r: int
:type c: int
:rtype: List[List[int]]
"""
row=len(nums)
colum=len(nums[0])
if row*colum!=r*c:
return nums
else:
tmp=[num for row in nums for num in row]
newarray=[[0 for j in range(c)]for i in range(r)]
for i in range(r):
for j in range(c):
newarray[i][j]=tmp[i*c+j]
return newarray