array - python find values within a range
Finding range of a numpy array elements (2)
This is a very simple question:
I have a numpy array of 94 x 155:
a = [1 2 20 68 210 290.. 2 33 34 55 230 340.. .. .. ... .. ... .....]
I want to calculate the range of each row..so that I get 94 ranges in a result. I tried looking for numpy.range function, which I don't think exists. If this can be done through a loop then its also good.
For example: Like we have numpy.mean() function, in which, if we set the axis parameter as 1, then it returns the mean for each row in the Nd array..
np.ptp might do what you want:
r = np.ptp(a,axis=1)
r is your range array.
def range(x, axis=0): return np.max(x, axis=axis) - np.min(x, axis=axis)