Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6991 > unrolled thread

100 rows and 100 columns random matrix

Started bySahar Nazemi <nazemisahar@yahoo.com>
First post2011-12-07 11:23 +0000
Last post2011-12-08 10:36 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  100 rows and 100 columns random matrix Sahar Nazemi <nazemisahar@yahoo.com> - 2011-12-07 11:23 +0000
    Re: 100 rows and 100 columns random matrix "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-12-08 10:23 +0000
    Re: 100 rows and 100 columns random matrix "Nasser M. Abbasi" <nma@12000.org> - 2011-12-08 10:32 +0000
    Re: 100 rows and 100 columns random matrix David Skulsky <edskulsky@gmail.com> - 2011-12-08 10:36 +0000

#6991 — 100 rows and 100 columns random matrix

FromSahar Nazemi <nazemisahar@yahoo.com>
Date2011-12-07 11:23 +0000
Subject100 rows and 100 columns random matrix
Message-ID<jbniam$497$1@smc.vnet.net>
Hello
I'm a student of geology who works with
Mathematica sofware .I'm learning it by myself recently.
I have a question and will appreciate if you
help me in this regard.
I have created a 100 rows and 100 columns random
matrix which its elements are between 0 to 1(for example it consists of
0.687,...).
Now I want to know how many of these elements
are in the range of "0 to 0.5" and how many are in the range of
"0.5 to 1".
I also use "Count" function as below
but it doesnt answer:
Count[a,{0,0.5}]
("a" is my random matrix).
Regards
Sahar Nazemi

[toc] | [next] | [standalone]


#7001

From"Dr. Wolfgang Hintze" <weh@snafu.de>
Date2011-12-08 10:23 +0000
Message-ID<jbq36a$ieb$1@smc.vnet.net>
In reply to#6991
Something like this works

(* set dimension of your matrix *)
n = 100;

(* create random matrix *)
a = Array[Random[] & , {n, n}];

(* flatten out matrix to get a 1 dimensional list *)
af = Flatten[a];

(* select numerical range *)
Select[af, #1 < 0.5 & ];

(* calculate length of the selection, i.e. number of elements of matrix 
in the selection range *)
Length[%]
5110

Regards,
Wolfgang

"Sahar Nazemi" <nazemisahar@yahoo.com> schrieb im Newsbeitrag 
news:jbniam$497$1@smc.vnet.net...
> Hello
> I'm a student of geology who works with
> Mathematica sofware .I'm learning it by myself recently.
> I have a question and will appreciate if you
> help me in this regard.
> I have created a 100 rows and 100 columns random
> matrix which its elements are between 0 to 1(for example it consists 
> of
> 0.687,...).
> Now I want to know how many of these elements
> are in the range of "0 to 0.5" and how many are in the range of
> "0.5 to 1".
> I also use "Count" function as below
> but it doesnt answer:
> Count[a,{0,0.5}]
> ("a" is my random matrix).
> Regards
> Sahar Nazemi 

[toc] | [prev] | [next] | [standalone]


#7021

From"Nasser M. Abbasi" <nma@12000.org>
Date2011-12-08 10:32 +0000
Message-ID<jbq3n1$ion$1@smc.vnet.net>
In reply to#6991
On 12/7/2011 5:23 AM, Sahar Nazemi wrote:
> Hello
> I'm a student of geology who works with
> Mathematica sofware .I'm learning it by myself recently.
> I have a question and will appreciate if you
> help me in this regard.
> I have created a 100 rows and 100 columns random
> matrix which its elements are between 0 to 1(for example it consists of
> 0.687,...).
> Now I want to know how many of these elements
> are in the range of "0 to 0.5" and how many are in the range of
> "0.5 to 1".
> I also use "Count" function as below
> but it doesnt answer:
> Count[a,{0,0.5}]
> ("a" is my random matrix).
> Regards
> Sahar Nazemi

The important thing to note is that some functions take
a 'pattern' to look for in a list (such as Cases, Position),
and some functions take a 'criteria' to look for in a list
(such as Select).

This is the first thing you need to decide on.

So, what you are looking for above is a criteria (#<0.5), and
not a pattern. Hence you can use Select

----------------
n  = 5; (*in your case this will be 100 *)
(a = Table[RandomReal[], {n}, {n}]) // MatrixForm
p  = Select[Flatten[a], # < 0.5 &];
m  = Length[p]
------------------------

If you want to use Cases, you can, but need to do a little
more work in order to make it a pattern so that Cases is happy

--------------------------------------
p = Cases[Flatten[a], x_ /; x < 0.5]
m = Length[p]
------------------------------------

Notice in all the above, Flatten was used to make the 'matrix'
into a 'vector'.

If you want to find the positions of these elements in the matrix,
then do

------------------------------
Position[a, x_ /; x < 0.5]
-----------------------------

If you want to replace those elements which are <0.5 in the matrix,
by another value, say Null, then do

-----------------------------------
p = Position[a, x_ /; x < 0.5];
a = ReplacePart[a, p -> Null]
-----------------------------------

To find how many are >=0.5, just take the difference

--------------------------------
n  = 5; (*in your case this will be 100 *)
(a = Table[RandomReal[], {n}, {n}]) // MatrixForm
p  = Select[Flatten[a], # < 0.5 &];
m  = Length[p];

n^2-m
-------------------------

--Nasser









[toc] | [prev] | [next] | [standalone]


#7029

FromDavid Skulsky <edskulsky@gmail.com>
Date2011-12-08 10:36 +0000
Message-ID<jbq3ur$iqj$1@smc.vnet.net>
In reply to#6991
a=RandomReal[{0, 1}, {100, 100}];
Count[Flatten[a],x_/;x<=0.5]

David

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web