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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:23:55+00:00 2026-06-08T09:23:55+00:00

I have a numpy array (actually imported from a GIS raster map) which contains

  • 0

I have a numpy array (actually imported from a GIS raster map) which contains
probability values of occurrence of a species like following example:

a = random.randint(1.0,20.0,1200).reshape(40,30)
b = (a*1.0)/sum(a)

Now I want to get a discrete version for that array again. Like if I have
e.g. 100 individuals which are located on the area of that array (1200 cells) how are they
distributed? Of course they should be distributed according to their probability,
meaning lower values indicated lower probability of occurrence. However, as everything is statistics there is still the chance that a individual is located at a low probability
cell. It should be possible that multiple individuals can occupy on cell…

It is like transforming a continuous distribution curve into a histogram again. Like many different histograms may result in a certain distribution curve it should also be the other way round. Accordingly applying the algorithm I am looking for will produce different discrete values each time.

…is there any algorithm in python which can do that? As I am not that familiar with discretization maybe someone can help.

  • 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-08T09:23:56+00:00Added an answer on June 8, 2026 at 9:23 am

    Use random.choice with bincount:

    np.bincount(np.random.choice(b.size, 100, p=b.flat),
                minlength=b.size).reshape(b.shape)
    

    If you don’t have NumPy 1.7, you can replace random.choice with:

    np.searchsorted(np.cumsum(b), np.random.random(100))
    

    giving:

    np.bincount(np.searchsorted(np.cumsum(b), np.random.random(100)),
                minlength=b.size).reshape(b.shape)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a numpy array which contains no data values. I mask those no
I have a numpy array which came from a cv2.imread and so has dtype
I have two identically-sized numpy.array objects (both one-dimensional), one of which contains a list
I have a 2D numpy array (i.e matrix) A which contains useful data interspread
I have an numpy array which I save to a image using savefig(). Then
I have a numpy array with positive and negative values in. a = array([1,1,-1,-2,-3,4,5])
I am creating an object in python. I have a numpy array from an
I have a 1D numpy array, and some offset/length values. I would like to
I have a 2D numpy array of shape (N,2) which is holding N points
I have a list of values and a 1-d numpy array, and I would

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.