reshape Function and flatten Method in Python