numpy - Finding the number of values that satisfy something in a matrix, without using loops. Python -
i write function takes 3 arguments: matrix 1, matrix 2, , number p. functions outputs number of entries in difference between matrix 1 , matrix 2 bigger p. instructed not use loops.
i advised use x.sum() function x ndarray.
i don't know here.
the first thing want subtract m2 m1. have entries, 1 of either or not bigger p.
i tried find way sum function, afraid can't see how can me.
the thing can think going through entries, not allowed to. appreciate in this. no recursion allowed well.
import pandas pd # pick value of p p = 20 # instantiate fake frames = pd.dataframe({'foo':[4, 10], 'bar':[34, -12]}) b = pd.dataframe({'foo':[64, 0], 'bar':[21, 354]}) # absolute value of difference c = (b - a).applymap(abs) # boolean slice, sum along each axis total number of "true"s c.applymap(lambda x: x > p).sum().sum()
Comments
Post a Comment