Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Matrix question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60311] Re: Matrix question
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Sat, 10 Sep 2005 22:36:33 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 9/10/05 at 6:46 AM, sandog at mail.gr (sandog) wrote:

>i want to create a NxN matrix with zeros but i want a percentage of
>the matrix spots to be one at random spots any idea? cause i have
>no clue how to do that. Any help appreciated thx .

One way to do this would be as follows

mat = SparseArray@Table[
       {Random[Integer,n],Random[Integer,n}->1,{Floor[p n^2]}]

where n is the size of the matrix you want and p is the percentage of ones you want. Note if p is large, there may be more efficient ways to achieve what you want than using SparseArray.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Matrix question
  • Next by Date: Re: Numerical integration over half-infinite intervals
  • Previous by thread: Re: Matrix question
  • Next by thread: Re: Matrix question