Issue
I have an array like: import numpy as np
a=np.array([[1,0,0,0,0,1],
[0,0,1,0,1,0],
[0,0,0,1,0,0],
[0,0,1,0,0,0]])
b=np.array([[0,0,0,0,0,1],
[0,0,1,0,1,1],
[1,0,0,0,0,1],
[0,0,1,0,0,1]])
Requirement:
where the elementvalue of 1 in an array 'a' is equal to element value of 1 in array 'b'.
Need to access the percentage of matching only with element value 1,not at zero
I tried with:
matching_error=(np.mean(a!=b)
Output:
0.25
# because out of 24 elements in an array 18 are matching(here 0,1 both the values are
in matching action), I need matching action at only element value 1
Required Output:
0.83
#because out of 24 elements, the element value is matching at 4 points
Solution
Since your data is (implicitly) binary, i.e. only consisting of 0
s and 1
s, one could use
1 - np.mean(a+b==2)
>0.8333333333333334
Answered By - 7shoe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.