fork(1) download
  1. import numpy as np
  2.  
  3. def Ratio(img):
  4. a = 0
  5. for row in range(len(img)):
  6. for col in range(len(img[0])):
  7. if img[row][col]==True:
  8. a = a+1
  9. total = img.shape[0] * img.shape[1]
  10. return a/total
  11.  
  12. a = np.array([[ 1, 0, 1, 1 ],[0, 1, 0, 1 ],[ 1, 1, 1, 0 ]])
  13.  
  14. print(Ratio(a))
Success #stdin #stdout 0.21s 27176KB
stdin
Standard input is empty
stdout
0.6666666666666666