yt.utilities.math_utils.
quartiles
(a, axis=None, out=None, overwrite_input=False)[source]¶Compute the quartile values (25% and 75%) along the specified axis in the same way that the numpy.median calculates the median (50%) value alone a specified axis. Check numpy.median for details, as it is virtually the same algorithm.
Returns an array of the quartiles of the array elements [lower quartile, upper quartile].
Parameters: | a : array_like
axis : {None, int}, optional
out : ndarray, optional
overwrite_input : {False, True}, optional
|
---|---|
Returns: | quartiles : ndarray
|
See also
Notes
Given a vector V of length N, the quartiles of V are the 25% and 75% values
of a sorted copy of V, V_sorted
- i.e., V_sorted[(N-1)/4]
and
3*V_sorted[(N-1)/4]
, when N is odd. When N is even, it is the average
of the two values bounding these values of V_sorted
.
Examples
>>> a = np.arange(100).reshape(10,10)
>>> a
array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
[30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
[40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
[50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
[60, 61, 62, 63, 64, 65, 66, 67, 68, 69],
[70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
[80, 81, 82, 83, 84, 85, 86, 87, 88, 89],
[90, 91, 92, 93, 94, 95, 96, 97, 98, 99]])
>>> mu.quartiles(a)
array([ 24.5, 74.5])
>>> mu.quartiles(a,axis=0)
array([[ 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.],
[ 65., 66., 67., 68., 69., 70., 71., 72., 73., 74.]])
>>> mu.quartiles(a,axis=1)
array([[ 1.5, 11.5, 21.5, 31.5, 41.5, 51.5, 61.5, 71.5, 81.5,
91.5],
[ 6.5, 16.5, 26.5, 36.5, 46.5, 56.5, 66.5, 76.5, 86.5,
96.5]])