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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:19:48+00:00 2026-05-26T17:19:48+00:00

In Mathematica 8, I want to define a discrete distribution with density mass given

  • 0

In Mathematica 8, I want to define a discrete distribution with density mass given as a list. For example,

In[1] f = ProbabilityDistribution[{2/3, 1/3}[[x]], {x, 1, 2, 1}];

This seems to work. However, this emitted a twice-repeated warning:

"Part::pspec: Part specification x is neither an integer nor a list of integers." 

Nevertheless, f seems to work correctly. This message got me thinking that there may be a better way to define the same distribution. How can I define a discrete distribution using a list but without invoking the warning?

  • 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-05-26T17:19:49+00:00Added an answer on May 26, 2026 at 5:19 pm

    Could convert the list of weights to a Piecewise, and feed that to ProbabilityDistribution.

    wts = {2/3, 1/3};
    toPiecewise[wts_, x_] := 
     Piecewise[MapIndexed[{#1, x == #2[[1]]} &, wts]]
    
    In[178]:= f = 
     ProbabilityDistribution[toPiecewise[wts, x], {x, 1, 2, 1}]
    
    Out[178]= ProbabilityDistribution[
     Piecewise[{{2/3, \[FormalX] == 1}, {1/3, \[FormalX] == 2}}, 0], 
       {\[FormalX], 1, 2, 1}]
    

    Daniel Lichtblau

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

Sidebar

Related Questions

Mathematica's list of built-in formats is pretty extensive; however, JSON is not on that
I have a mathematica list in which I want to replace all 2s with
I want to implement this in Mathematica: I realize I can use ParametricPlot to
I want to overload Times and Plus for matrix multiplication in mathematica, for example,
What is the best way to define a numerical constant in Mathematica? For example,
This is another simple 'matrix' question in Mathematica. I want to show how I
The problem is that I want to output Mathematica compatible floating point numbers. The
I want to store a list of numbers (essentially, a set in mathematical terms)
In Mathematica I have a list: x = {1,2,3,3,4,5,5,6} How will I make a
I want to use mathematica to analyze some data of sqlite? But i don't

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.