from typing import List, Tuple, Union
import numpy as np
def reshape_matrix(a: List[List[Union[int, float]]], new_shape: Tuple[int, int]) -> List[List[Union[int, float]]]:
arr = np.array(a)
original_elements = arr.size
new_elements = new_shape[0] * new_shape[1]
if original_elements != new_elements:
return -1
reshaped_arr = arr.reshape(new_shape)
return reshaped_arr.tolist()
def main():
try:
a = eval(input())
new_shape = eval(input())
result = reshape_matrix(a, new_shape)
print(result)
except Exception as e:
print(f"输入格式错误: {e}")
if __name__ == "__main__":
main()