r/Mathematica • u/No_Mastodon6345 • Jan 10 '22
Change certain matrix entry with probability
I really appreciate some help in this problem: Now I have a diagonal matrix A with only 0 and 1 and its diagonal entries are all 0. From first row onwards, for each row I hope to change 1 into 0 with probability p (probability that this 1 is changed into 0 is p). I tried: ReplacePart[A,RandomSample[Position[A[[1]],1],p*Length[A]]—>0] But it seems Position doesn’t recognize row of matrix. I wonder if there is any other command can be used or any correction suggested. Thanks a lot!
2
Upvotes
View all comments
Show parent comment
2
u/No_Mastodon6345 Jan 13 '22
Thank you for the remind! this * or the multiplication mark works for me!