0

I am trying to compare two numpy arrays to see how good my prediction is.

The arrays are 2 dimensional in a 32bit float format. The problem is, in order to get the scores I need to divide the prediction value by the groundtruth value and there are zeros for those places in the gt array I do not have a value. Therefor I get an error.

anybody any idea how I can swing that?

1 Answers1

0

As discribed in this Post you should be able to use:

c = np.divide(a, b, out=np.zeros_like(a), where=b!=0)
Tom S
  • 591
  • 1
  • 5
  • 21
  • Thank you for the quick anwer! How ever in order to compue for example the mean relative error, the result of the division can't be zero, that would influence the score, so the computation has to skip when ever there is a zero value in the groundtruth – stillzero Jan 20 '21 at 10:47
  • Do you plan on doing mean relative error "by hand". If so just always use the "where=b!=0". – Tom S Jan 20 '21 at 10:56
  • abs_rel = np.mean(np.abs(gt - pred) / gt) sq_rel = np.mean(((gt - pred)**2) / gt) is this "by hand" – stillzero Jan 20 '21 at 11:11