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 8147217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:16:35+00:00 2026-06-06T14:16:35+00:00

I am attempting to extract Weibull distribution parameters (shape ‘k’ and scale ‘lambda’) that

  • 0

I am attempting to extract Weibull distribution parameters (shape ‘k’ and scale ‘lambda’) that satisfy a certain mean and variance. In this example, the mean is 4 and the variance is 8. It is a 2-unknowns and 2-equations type of problem.

Since this algorithm works with Excel 2010’s GRG Solver, I am certain it is about the way I am framing the problem, or potentially, the libraries I am using. I am not overly familiar with optimization libraries, so please let me know where the error is.

Below is the script:

from scipy.optimize import fmin_cg
import math

def weibull_mu(k, lmda):                  #Formula can be found on wikipedia
    return lmda*math.gamma(1+1/k)
def weibull_var(k, lmda):                 #Formula can be found on wikipedia
    return lmda**2*math.gamma(1+2/k)-weibull_mu(k, lmda)**2

def min_function(arggs):
    actual_mean = 4                          # specific to this example
    actual_var = 8                           # specific to this example
    k = arggs[0]
    lmda = arggs[1]
    output = [weibull_mu(k, lmda)-(var_wei)]
    output.append(weibull_var(k, lmda)-(actual_var)**2-(actual_mean)**2)
    return output

print fmin(min_function, [1,1])

This script gives me the following error:

[...]
  File "C:\Program Files\Python27\lib\site-packages\scipy\optimize\optimize.py", line 278, in fmin
    fsim[0] = func(x0)
ValueError: setting an array element with a sequence.
  • 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-06T14:16:36+00:00Added an answer on June 6, 2026 at 2:16 pm

    I managed to get it to work thanks to Anders Gustafsson’s comment (thank you). This script now works if one returns only a scalar (in this case I used something along the lines of least-squares). Also, bounds were added by changing the optimization function to “fmin_l_bfgs_b” (again, thanks to Anders Gustafsson).

    I only changed the min_function definition relative to the question.

    from scipy.optimize import fmin_l_bfgs_b
    import math
    
    def weibull_mu(k, lmda):
        return lmda*math.gamma(1+1/k)
    def weibull_var(k, lmda):
        return lmda**2*math.gamma(1+2/k)-weibull_mu(k, lmda)**2
    
    def min_function(arggs):
        actual_mean = 4.                    # specific to this example
        actual_var = 8.                     # specific to this example
        k = arggs[0]
        lmda = arggs[1]
        extracted_var = weibull_var(k, lmda)
        extracted_mean = weibull_mu(k, lmda)
        output = (extracted_var - actual_var)**2 + (extracted_mean - actual_mean)**2
        return output
    
    print fmin_l_bfgs_b(min_function, best_guess, approx_grad = True, bounds = [(.0000001,None),(.0000001,None)], disp = False)
    

    Note: Please feel free to use this script for your own or professional use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have about 4,000 word docs that I'm attempting to extract the text
I'm attempting to extract the URL parameters via regex and am sooo close to
I am attempting to extract all instances of a particular format from a string:
Attempting to make a NSObject called 'Person' that will hold the login details for
I'm attempting to extract a given pattern within a text file, however, the results
I just found a weird behavior when attempting to extract a string from the
I am attempting to scrape a web page that has the following structures within
I am attempting to use BeautifulSoup to parse through a DOM tree and extract
Hey, I am attempting to use the Microsoft.MSHTML (Version 7.0.3300.0) library to extract the
I am attempting to extract the raw bytes of a private key stored in

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.