2
$\begingroup$
MustarandSigmastar = Join[Mustar, VectorofSigmastar];
    z = Table[
       RandomVariate[
        NormalDistribution[MustarandSigmastar[[i]], 
         MustarandSigmastar[[j]]], n], {i, 1, m}, {j, m + 1, 2m}];

How to generate only m pairs of parameters? Thanks

$\endgroup$
2
  • 2
    $\begingroup$ Which pairs do you want? Do you want pairs like {first, 1+mth}, {second,2+mth}, etc? Also, please fix your code by providing definitions for all symbols. Without this, we're left making our own test cases and guessing what those should be for your context. And speaking of test cases, sample inputs with expected outputs would make it even clearer what you're hoping to achieve. $\endgroup$
    – lericr
    Dec 10, 2022 at 19:29
  • $\begingroup$ Please post an example. $\endgroup$
    – cvgmt
    Dec 11, 2022 at 2:28

3 Answers 3

2
$\begingroup$
m = 10;
mustar = RandomReal[{-1, 1}, m]
sigmastar = RandomReal[{0, 1}, m]
z = MapThread[RandomVariate[NormalDistribution[#1, #2]] &, {mustar, sigmastar}]

Make RandomVariate pick as many as you wish. If you meant that you wanted existing parameter lists to be randomly paired, just replace mustar with RandomSample@mustar.

$\endgroup$
1
$\begingroup$
Clear["Global`*"]

m = 5;
n = 4;

MustarandSigmastar = RandomReal[1, 2 m];

param =
  RandomChoice[
   Outer[{#1, #2} &,
     MustarandSigmastar[[;; m]],
     MustarandSigmastar[[m + 1 ;;]]] //
    Flatten[#, 1] &,
   m];

z = RandomVariate[
    NormalDistribution @@ #, n] & /@
  param

(* {{0.707468, 0.736669, 0.708138, 0.721982}, 
    {0.40102, 0.430933, 0.425616, 0.414167}, 
    {0.557164, 0.480605, 0.523246, 0.462627}, 
    {0.711562, 0.710971, 0.780158, 0.665663}, 
    {1.17702, 1.01058, 0.908726, 0.706781}} *)
$\endgroup$
0
$\begingroup$
MustarandSigmastar = Inner[List, Mustar, Sigmastar, List];
z = Table[
   RandomVariate[
    NormalDistribution[MustarandSigmastar[[i]][[1]], 
     MustarandSigmastar[[i]][[2]]], n], {i, 1, m}];

(This is how I addressed it.)
$\endgroup$
1
  • $\begingroup$ Simpler and more idiomatic approaches are available. $\endgroup$
    – Alan
    Dec 12, 2022 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.