24

1D Histogram

Unsolved
Data Wrangling
Fundamentals

Difficulty: 2 | Problem written by Sakar Ghimire
A histogram represents the frequency distribution of data. The idea is to take a list of values and make a tally of how many times each value occurs.

Given a 1D NumPy array, create a histogram of the data represented as a NumPy array where the index represents the number and the value represents the count. Note that the first index (position 0) represents how many times number 1 occurs.

There are 2 things to note:

  • The parameter range default from min to max, however the task requires histogram starting from 1.
  • bins default to only 10 values, therefore we must set it to max cover all the numbers in the np.array
Sample Input:
<class 'list'>
arr: [1, 1, 1, 2, 2, 3, 5, 6, 7, 8, 9, 6, 8, 9, 7, 2, 9]

Expected Output:
<class 'numpy.ndarray'>
[3. 3. 1. 0. 1. 2. 2. 2. 3.]

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Quis dolore corporis adipisci. Adipisci doloremque atque laborum reprehenderit minus sed et voluptate non omnis quaerat, rem officia sint corporis odio eius expedita eaque esse, reiciendis nam deleniti distinctio saepe porro aperiam voluptatem iste?

Cumque unde eum aliquam ea, et eius porro maxime id deleniti atque, dolor sed harum sapiente error. Quo quibusdam harum modi suscipit ex dolor laudantium provident ipsa qui, ipsa eligendi laudantium tempore neque hic, harum nesciunt fuga porro consectetur, illo error quibusdam sequi dolorum.

Reiciendis id aut et, labore fugiat beatae at ratione reprehenderit modi quasi voluptate.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)