Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:35:53+00:00 2026-06-15T01:35:53+00:00

I have a homework problem in which I’m supposed to write a function for

  • 0

I have a homework problem in which I’m supposed to write a function for Kurtosis as descirbed here:

Kurtosis, where theta is the standard deviation

The theta in the denominator is the standard deviation (square-root of the variance) and the x-with-the-bar in the numerator is the mean of x.

I’ve implemented the function as follows:

import numpy as np
from scipy.stats import kurtosis

testdata = np.array([1, 2, 3, 4, 5])

def mean(obs):
    return (1. / len(obs)) * np.sum(obs)

def variance(obs):
    return (1. / len(obs)) * np.sum((obs - mean(obs)) ** 2)

def kurt(obs):
    num = np.sqrt((1. / len(obs)) * np.sum((obs - mean(obs)) ** 4))
    denom = variance(obs) ** 2  # avoid losing precision with np.sqrt call
    return num / denom

The first two functions, mean and variance were successfully cross-validated with numpy.mean and numpy.var, respectively.

I attempted to cross-validate kurt with the following statement:

>>> kurtosis(testdata) == kurt(testdata)
False

Here’s the output of both kurtosis functions:

>>> kurtosis(testdata)  # scipy.stats
-1.3

>>> kurt(testdata)  # my crappy attempt
0.65192024052026476

Where did I go wrong? Is scipy.stats.kurtosis doing something fancier than what’s in the equation I’ve been given?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:35:55+00:00Added an answer on June 15, 2026 at 1:35 am

    By default, scipy.stats.kurtosis():

    1. Computes excess kurtosis (i.e. subtracts 3 from the result).
    2. Corrects for statistical biases (this affects some of the denominators).

    Both behaviours are configurable through optional arguments to scipy.stats.kurtosis().

    Finally, the np.sqrt() call in your method is unnecessary since there’s no square root in the formula. Once I remove it, the output of your function matches what I get from kurtosis(testdata, False, False).

    I attempted to cross-validate kurt with the following statement

    You shouldn’t be comparing floating-point numbers for exact equality. Even if the mathematical formulae are the same, small differences in how they are translated into computer code could affect the result of the computation.

    Finally, if you’re going to be writing numerical code, I strongly recommend reading What Every Computer Scientist Should Know About Floating-Point Arithmetic.

    P.S. This is the function I’ve used:

    In [51]: def kurt(obs):
       ....:     num = np.sum((obs - mean(obs)) ** 4)/ len(obs)
       ....:     denom = variance(obs) ** 2  # avoid losing precision with np.sqrt call
       ....:     return num / denom
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about my homework problem. Here is the problem: Write a
I have a homework problem here I've been working on; here is the description:
I have a homework assignment that I am supposed to write a http server
I have a homework problem in which I need to remove all the green
I have a homework problem, in which I have a class Student , and
I have a homework assignment to write a multi-threaded sudoku solver, which finds all
This was a homework assignment problem which I know I have incorrectly answered. I
Okay, so I have another question on a prolog homework problem I am struggling
I have a homework question that says: Problem 1: Given the array [ 22
I am doing homework but I have problem with non-RestFul routes. My spec is:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.