_percentile
percentile
¶
Compute the percentiles
of a tensor
.
The n-th percentile of tensor
is the value n/100 of the way from the minimum to the maximum in a sorted copy of
tensor
. If the percentile falls in between two values, the lower of the two values will be used.
This method can be used with Numpy data:
n = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
b = fe.backend.percentile(n, percentiles=[66]) # [[[6]]]
b = fe.backend.percentile(n, percentiles=[66], axis=0) # [[[4, 5, 6]]]
b = fe.backend.percentile(n, percentiles=[66], axis=1) # [[[2], [5], [8]]]
This method can be used with TensorFlow tensors:
t = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
b = fe.backend.percentile(t, percentiles=[66]) # [[[6]]]
b = fe.backend.percentile(t, percentiles=[66], axis=0) # [[[4, 5, 6]]]
b = fe.backend.percentile(t, percentiles=[66], axis=1) # [[[2], [5], [8]]]
This method can be used with PyTorch tensors:
p = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
b = fe.backend.percentile(p, percentiles=[66]) # [[[6]]]
b = fe.backend.percentile(p, percentiles=[66], axis=0) # [[[4, 5, 6]]]
b = fe.backend.percentile(p, percentiles=[66], axis=1) # [[[2], [5], [8]]]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor |
Tensor
|
The tensor from which to extract percentiles. |
required |
percentiles |
Union[int, List[int]]
|
One or more percentile values to be computed. |
required |
axis |
Union[None, int, List[int]]
|
Along which axes to compute the percentile (None to compute over all axes). |
None
|
keepdims |
bool
|
Whether to maintain the number of dimensions from |
True
|
Returns:
Type | Description |
---|---|
Tensor
|
The |
Raises:
Type | Description |
---|---|
ValueError
|
If |