Create a function called histogram that takes as input a

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[0] will represent values in the range (b, b + w), hist[1] 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).
Return hist.

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)
should return
[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)
should return
[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

Related Posts

Quality Writing Features

Price Start $10
  • 24/7 Customer Support
  • All Subject Areas
  • Money-Back Guarantee
  • Timely Delivery
  • Originality report
  • Confidentiality guaranteed

Ordering Homework Writing Service

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.


Submit Requirements

Fill in your assignment instructions on the order form


Writer match

Immediately you contact us for homework help; we will assign your assignment to an academic expert.


Quality review

We have a team of editors, who will thoroughly review your assignment, ensuring there are no errors before submission


Get Your Completed Paper

Once we have completed the assignment, we will deliver it to your account. Additionally, we will send a notification to your email.



Budget-friendly writing services



We don’t share our client’s information with a third party



We write every assignment from scratch

Amazing Homework Writing Features

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.

Free Homework Writing Services

Free plagiarism checker

You can confirm that the content you get is original for free using our plagiarism checker.

Free samples

We offer unlimited access to our essay homework samples.

Free title page and bibliography

Once you place an order, we format it accordingly without demanding additional charges.

Free unlimited revisions

We offer free unlimited revisions until your assignment is of your desired quality..

Free editing and proofreading

We have a team of specialized editors who review your assignment before submission.

Free customer support

You can track the progress of your homework for free.

Request for Homework Writing Service Today!

We have over 500 homework writing experts, ready and waiting to help you improve your writing skills