NumPy: Compute the 80th percentile for all elements in a given array along the second axis
NumPy Statistics: Exercise-4 with Solution
Write a NumPy program to compute the 80th percentile for all elements in a given array along the second axis.
import numpy as np x = np.arange(12).reshape((2, 6)) print("\nOriginal array:") print(x) r1 = np.percentile(x, 80, 1) print("\n80th percentile for all elements of the said array along the second axis:") print(r1)
Original array: [[ 0 1 2 3 4 5] [ 6 7 8 9 10 11]] 80th percentile for all elements of the said array along the second axis: [ 4. 10.]
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a NumPy program to calculate the difference between the maximum and the minimum values of a given array along the second axis.
Next: Write a NumPy program to compute the median of flattened given array.
What is the difficulty level of this exercise?
- New Content published on w3resource :
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework