fork download
  1. import numpy as np
  2.  
  3. def _mask(r_width, r_hight):
  4. mask = np.zeros((r_hight, r_width), dtype=int)
  5. x_mid = int(r_width / 2)
  6. y_mid = int(r_hight / 2)
  7. x_step = (r_width-1) / (r_hight-1)
  8.  
  9. for y in range(y_mid):
  10. mask[y][x_mid - int(x_step * y) - 1 : x_mid + int(x_step * y) + 1] = 1
  11. for y in range(y_mid, r_hight):
  12. mask[y][x_mid - int(x_step * (r_hight - y)) : x_mid + int(x_step * (r_hight - y)) + 1] = 1
  13.  
  14. return mask
  15.  
  16. print(_mask(6,7), _mask(7,7), _mask(8,8), sep="\n\n")
  17.  
Success #stdin #stdout 0.19s 27148KB
stdin
Standard input is empty
stdout
[[0 0 1 1 0 0]
 [0 0 1 1 0 0]
 [0 1 1 1 1 0]
 [1 1 1 1 1 1]
 [0 1 1 1 1 1]
 [0 0 1 1 1 0]
 [0 0 0 1 0 0]]

[[0 0 1 1 0 0 0]
 [0 1 1 1 1 0 0]
 [1 1 1 1 1 1 0]
 [0 0 0 0 0 0 1]
 [1 1 1 1 1 1 1]
 [0 1 1 1 1 1 0]
 [0 0 1 1 1 0 0]]

[[0 0 0 1 1 0 0 0]
 [0 0 1 1 1 1 0 0]
 [0 1 1 1 1 1 1 0]
 [1 1 1 1 1 1 1 1]
 [1 1 1 1 1 1 1 1]
 [0 1 1 1 1 1 1 1]
 [0 0 1 1 1 1 1 0]
 [0 0 0 1 1 1 0 0]]