Create a function called histogram that takes as input a dataset data, a lower bound b, an upper bound h, and a number of bins n, and returns a histogram representation of data with n bins between these bounds. More specifically, your function should:
Have input arguments histogram(data, n, b, h), expecting data as a list of floats, n as an integer, and b and h as floats.
Print the error message b and h are the same value and return an empty list if b and h are the same number (the width of the histogram is 0)
If b is larger than h, re-assign b to h and h to b.
If n is equal to 0, return an empty list
Initialize the histogram hist as a list of n zeros.
Calculate the bin width as w = (h-b)/n, so that hist will represent values in the range (b, b + w), hist in the range [b + w, b + 2w), and so on through hist[n-1]. (Remember that [ is inclusive while ) is not!).
Ignore any values in data that are less than or equal to b and greater than or equal to h. *Remember if you have changed h and b in step 3, you would need to work with the new value of h and b .
Increment hist[i] by 1 for each value in data that belongs to bin i, i.e., in the range [b + i*w, b + (i+1)*w).
At the beginning of your function, be sure to check that n is a positive integer; if not, your code should just return an empty list for hist. Please remember to return an empty list.
For example, typing in
data = [-2, -2.2, 0, 5.6, 8.3, 10.1, 30, 4.4, 1.9, -3.3, 9, 8] hist = histogram(data, 15, -5, 10) print(hist)
[0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 2, 1]
Some other test cases are:
data = [-4, -3.2, 0, 7.6, 1.0, 2.2, 30, 2.2, 1.9, -8.3, 6, 5] hist = histogram(data, 10, 10, 0) print(hist)
[0, 2, 2, 0, 0, 1, 1, 1, 0, 0]
data = [2,2,2] hist = histogram(data, 5, -2, 3) print(hist)
[0, 0, 0, 0, 3]
data = [-1,-1,-1,10,10] hist = histogram(data, 5, -1, 10) print(hist)
[0, 0, 0, 0, 0]
Note: Please include all conditions specified in this problem into your code.
Welcome to one of the bestassignmenthelpcompanies online .
Do you want to order for a customized assignment help task?
Click on the order now button
Set up your topic, Fix the number of pages, Fix your Order instructions
Set up your deadline, upload the necessary files required to complete the task, Complete the payment.
We delivery high quality and non plagiarized tasks within the stipulated time given
You can get our ideal online homework help services with four easy steps. All you have to do is inform us of your requirements. Immediately we will match with a specialist in your academic discipline. After that, we will track your order, review it to ensure it meets your requirements, and submit it to your email.
Fill in your assignment instructions on the order form
Immediately you contact us for homework help; we will assign your assignment to an academic expert.
We have a team of editors, who will thoroughly review your assignment, ensuring there are no errors before submission
Once we have completed the assignment, we will deliver it to your account. Additionally, we will send a notification to your email.
Once you consult us for homework help online services, you will attest to why we are among the USA's best essay writing services.
Read on and find out some of the features that make our services superlative.
You can confirm that the content you get is original for free using our plagiarism checker.
We offer unlimited access to our essay homework samples.
Once you place an order, we format it accordingly without demanding additional charges.
We offer free unlimited revisions until your assignment is of your desired quality..
We have a team of specialized editors who review your assignment before submission.
You can track the progress of your homework for free.