ag.py 553 B

12345678910111213141516171819202122232425
  1. import numpy as np
  2. add_tuple = lambda a, b: tuple(a_i + b_i for a_i, b_i in zip(a, b))
  3. def shift(a, pos):
  4. shift_x, shift_y = pos
  5. c = np.zeros(add_tuple(a.shape, (shift_y, shift_x)), dtype=int)
  6. c[shift_y:,shift_x:] = a
  7. return c
  8. def max_shape(shape_a, shape_b):
  9. a_n, a_m = shape_a
  10. b_n, b_m = shape_b
  11. return (max(a_n, b_n), max(a_m, b_m))
  12. def add_shape(shape_a, shape_b):
  13. a_n, a_m = shape_a
  14. b_n, b_m = shape_b
  15. return (a_n + b_n, a_m + b_m)
  16. a = np.array([
  17. [1, 2, 3],
  18. [7, 8, 9]
  19. ])
  20. print(shift(a, (2, 1)))