Advertisement
furas

Python - Numpy - array quarter

May 9th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import numpy as np
  2.  
  3. arr = np.array([
  4.     [1,1,2,2],
  5.     [1,1,2,2],
  6.     [3,3,4,4],
  7.     [3,3,4,4], # try to remove this line and run it again
  8. ])
  9.  
  10. h, w = arr.shape # height, width
  11. mh = h//2 # middle of height (more or less)
  12. mw = w//2 # middle of width (more or less)
  13.  
  14. number = input('number: ')
  15. if number == '1':
  16.     print('1:', arr[:mh,:mw])
  17. elif number == '2':    
  18.     print('2:', arr[:mh,mw:])
  19. elif number == '3':    
  20.     print('3:', arr[mh:,:mw])
  21. elif number == '4':    
  22.     print('4:', arr[mh:,mw:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement