Generating non-random normally distributed values between two pointspython, weighted linspaceLimiting floats to two decimal pointsRandom string generation with upper case letters and digitsDifference between Python's Generators and IteratorsGet difference between two listsGenerate random integers between 0 and 9Differences between distribute, distutils, setuptools and distutils2?Fitting a Normal distribution to 1D dataHow do you set the 'tail probabilities' in a scipy genextreme distribution?How to obtain a python scipy-type continuous rv distribution object that is bounded?Generating random number in a non-normal distribution with Python

How to write a convincing religious myth?

Who won a Game of Bar Dice?

Does putting salt first make it easier for attacker to bruteforce the hash?

Are polynomials with the same roots identical?

Fermat's statement about the ancients: How serious was he?

Has there been a multiethnic Star Trek character?

Electricity free spaceship

Why did Intel abandon unified CPU cache?

Separate SPI data

Does the Nuka-Cola bottler actually generate nuka cola?

A word that means "blending into a community too much"

If I leave the US through an airport, do I have to return through the same airport?

Was Self-modifying-code possible just using BASIC?

A map of non-pathological topology?

Should I refuse to be named as co-author of a low quality paper?

Is Lambda Calculus purely syntactic?

Who voices the small round football sized demon In Good Omens

Teaching a class likely meant to inflate the GPA of student athletes

Do you have to have figures when playing D&D?

Does the new finding on "reversing a quantum jump mid-flight" rule out any interpretations of QM?

Is using 'echo' to display attacker-controlled data on the terminal dangerous?

UTC timestamp format for launch vehicles

Sci-fi novel: ark ship from Earth is sent into space to another planet, one man woken early from cryosleep paints a giant mural

Swimming Pool Staff/Patron Structure



Generating non-random normally distributed values between two points


python, weighted linspaceLimiting floats to two decimal pointsRandom string generation with upper case letters and digitsDifference between Python's Generators and IteratorsGet difference between two listsGenerate random integers between 0 and 9Differences between distribute, distutils, setuptools and distutils2?Fitting a Normal distribution to 1D dataHow do you set the 'tail probabilities' in a scipy genextreme distribution?How to obtain a python scipy-type continuous rv distribution object that is bounded?Generating random number in a non-normal distribution with Python






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I've stumbled across this code in an answer to a question and I'd like to automate the process of getting the distribution to fit neatly between two bounds.



import numpy as np
from scipy import stats

bounds = [0, 100]
n = np.mean(bounds)
# your distribution:
distribution = stats.norm(loc=n, scale=20)

# percentile point, the range for the inverse cumulative distribution function:
bounds_for_range = distribution.cdf(bounds)

# Linspace for the inverse cdf:
pp = np.linspace(*bounds_for_range, num=1000)

x = distribution.ppf(pp)

# And just to check that it makes sense you can try:
from matplotlib import pyplot as plt
plt.hist(x)
plt.show()


Let's say I have the values [720, 965], or any other bounds, that I would like to fit my distribution across. Is there a way to soft-code the adjustment of scale in stats.norm to fit this distribution across my bounds without any unreasonable gaps? Or are there any functions that have this type of functionality?



A scale of ~20 works well for the example code, but I have to adjust it to ~50 for the example of [720, 965]










share|improve this question

















  • 1





    Is scale=(bounds[1] - bounds[0]) * 0.2 good enough?

    – Elias Strehle
    Mar 24 at 21:25


















0















I've stumbled across this code in an answer to a question and I'd like to automate the process of getting the distribution to fit neatly between two bounds.



import numpy as np
from scipy import stats

bounds = [0, 100]
n = np.mean(bounds)
# your distribution:
distribution = stats.norm(loc=n, scale=20)

# percentile point, the range for the inverse cumulative distribution function:
bounds_for_range = distribution.cdf(bounds)

# Linspace for the inverse cdf:
pp = np.linspace(*bounds_for_range, num=1000)

x = distribution.ppf(pp)

# And just to check that it makes sense you can try:
from matplotlib import pyplot as plt
plt.hist(x)
plt.show()


Let's say I have the values [720, 965], or any other bounds, that I would like to fit my distribution across. Is there a way to soft-code the adjustment of scale in stats.norm to fit this distribution across my bounds without any unreasonable gaps? Or are there any functions that have this type of functionality?



A scale of ~20 works well for the example code, but I have to adjust it to ~50 for the example of [720, 965]










share|improve this question

















  • 1





    Is scale=(bounds[1] - bounds[0]) * 0.2 good enough?

    – Elias Strehle
    Mar 24 at 21:25














0












0








0








I've stumbled across this code in an answer to a question and I'd like to automate the process of getting the distribution to fit neatly between two bounds.



import numpy as np
from scipy import stats

bounds = [0, 100]
n = np.mean(bounds)
# your distribution:
distribution = stats.norm(loc=n, scale=20)

# percentile point, the range for the inverse cumulative distribution function:
bounds_for_range = distribution.cdf(bounds)

# Linspace for the inverse cdf:
pp = np.linspace(*bounds_for_range, num=1000)

x = distribution.ppf(pp)

# And just to check that it makes sense you can try:
from matplotlib import pyplot as plt
plt.hist(x)
plt.show()


Let's say I have the values [720, 965], or any other bounds, that I would like to fit my distribution across. Is there a way to soft-code the adjustment of scale in stats.norm to fit this distribution across my bounds without any unreasonable gaps? Or are there any functions that have this type of functionality?



A scale of ~20 works well for the example code, but I have to adjust it to ~50 for the example of [720, 965]










share|improve this question














I've stumbled across this code in an answer to a question and I'd like to automate the process of getting the distribution to fit neatly between two bounds.



import numpy as np
from scipy import stats

bounds = [0, 100]
n = np.mean(bounds)
# your distribution:
distribution = stats.norm(loc=n, scale=20)

# percentile point, the range for the inverse cumulative distribution function:
bounds_for_range = distribution.cdf(bounds)

# Linspace for the inverse cdf:
pp = np.linspace(*bounds_for_range, num=1000)

x = distribution.ppf(pp)

# And just to check that it makes sense you can try:
from matplotlib import pyplot as plt
plt.hist(x)
plt.show()


Let's say I have the values [720, 965], or any other bounds, that I would like to fit my distribution across. Is there a way to soft-code the adjustment of scale in stats.norm to fit this distribution across my bounds without any unreasonable gaps? Or are there any functions that have this type of functionality?



A scale of ~20 works well for the example code, but I have to adjust it to ~50 for the example of [720, 965]







python numpy scipy






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 20:42









EstifEstif

245




245







  • 1





    Is scale=(bounds[1] - bounds[0]) * 0.2 good enough?

    – Elias Strehle
    Mar 24 at 21:25













  • 1





    Is scale=(bounds[1] - bounds[0]) * 0.2 good enough?

    – Elias Strehle
    Mar 24 at 21:25








1




1





Is scale=(bounds[1] - bounds[0]) * 0.2 good enough?

– Elias Strehle
Mar 24 at 21:25






Is scale=(bounds[1] - bounds[0]) * 0.2 good enough?

– Elias Strehle
Mar 24 at 21:25













1 Answer
1






active

oldest

votes


















0














I am not sure, but truncated normal distribution should be exactly what you are looking for.



from scipy.stats import truncnorm
distr_ab = truncnorm(a, b) # truncated normal distribution in the interval [a, b]
distr_ab.rvs(size=100) # get 100 samples from the distribution
# distr_ab.cdf, distr_ab.ppf etc... all accessible





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328380%2fgenerating-non-random-normally-distributed-values-between-two-points%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I am not sure, but truncated normal distribution should be exactly what you are looking for.



    from scipy.stats import truncnorm
    distr_ab = truncnorm(a, b) # truncated normal distribution in the interval [a, b]
    distr_ab.rvs(size=100) # get 100 samples from the distribution
    # distr_ab.cdf, distr_ab.ppf etc... all accessible





    share|improve this answer



























      0














      I am not sure, but truncated normal distribution should be exactly what you are looking for.



      from scipy.stats import truncnorm
      distr_ab = truncnorm(a, b) # truncated normal distribution in the interval [a, b]
      distr_ab.rvs(size=100) # get 100 samples from the distribution
      # distr_ab.cdf, distr_ab.ppf etc... all accessible





      share|improve this answer

























        0












        0








        0







        I am not sure, but truncated normal distribution should be exactly what you are looking for.



        from scipy.stats import truncnorm
        distr_ab = truncnorm(a, b) # truncated normal distribution in the interval [a, b]
        distr_ab.rvs(size=100) # get 100 samples from the distribution
        # distr_ab.cdf, distr_ab.ppf etc... all accessible





        share|improve this answer













        I am not sure, but truncated normal distribution should be exactly what you are looking for.



        from scipy.stats import truncnorm
        distr_ab = truncnorm(a, b) # truncated normal distribution in the interval [a, b]
        distr_ab.rvs(size=100) # get 100 samples from the distribution
        # distr_ab.cdf, distr_ab.ppf etc... all accessible






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 1:48









        bubblebubble

        1,180713




        1,180713



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328380%2fgenerating-non-random-normally-distributed-values-between-two-points%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해