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

  • Home
  • SEARCH
  • 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 8231021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:20:01+00:00 2026-06-07T17:20:01+00:00

Does anyone have suggestions for efficiently truncating the SciPy random distributions. For example, if

  • 0

Does anyone have suggestions for efficiently truncating the SciPy random distributions. For example, if I generate random values like so:

import scipy.stats as stats
print stats.logistic.rvs(loc=0, scale=1, size=1000)

How would I go about constraining the output values between 0 and 1 without changing the original parameters of the distribution and without changing the sample size, all while minimizing the amount of work the machine has to do?

  • 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-07T17:20:03+00:00Added an answer on June 7, 2026 at 5:20 pm

    Your question is more of a statistics question than a scipy question. In general, you would need to be able to normalize over the interval you are interested in and compute the CDF for this interval analytically to create an efficient sampling method. Edit: And it turns out that this is possible (rejection sampling is not needed):

    import scipy.stats as stats
    
    import matplotlib.pyplot as plt
    import numpy as np
    import numpy.random as rnd
    
    #plot the original distribution
    xrng=np.arange(-10,10,.1)
    yrng=stats.logistic.pdf(xrng)
    plt.plot(xrng,yrng)
    
    #plot the truncated distribution
    nrm=stats.logistic.cdf(1)-stats.logistic.cdf(0)
    xrng=np.arange(0,1,.01)
    yrng=stats.logistic.pdf(xrng)/nrm
    plt.plot(xrng,yrng)
    
    #sample using the inverse cdf
    yr=rnd.rand(100000)*(nrm)+stats.logistic.cdf(0)
    xr=stats.logistic.ppf(yr)
    plt.hist(xr,density=True)
    
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any suggestions on how to edit an <a href=''> link in
Does anyone have a suggestions for a superb cool image gallery that I can
Does anyone have any suggestions about where I can find a C# implementation for
Does anyone have suggestions for how to extend specifically Python 3 with C++? I've
More specifically making HTML, Java, and python more readable? Does anyone have suggestions for
Does anyone have suggestions how to do this? I have an array in my
Does anyone have suggestions on automated ways to verify that backlinks are valid? I
Does anyone have any suggestions for an 'Apple Sanctioned' way to change behaviors (ie,
Does anyone have suggestions how to implement a widget similar to mac's finder in
Does anyone have a translate function for x/y positions after rotation in javascript? for

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.