MathGroup Archive 2009

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

Search the Archive

Re: Two questions about modification of a matrix.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101052] Re: [mg101041] Two questions about modification of a matrix.
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Tue, 23 Jun 2009 07:02:25 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

mat = Table[RandomReal[{-1, 1}], {7}, {5}]

mat2 = mat*Table[If[i*j > 6, 0, 1],
   {i, Length[mat]}, {j, Length[mat[[1]]]}]

mat3 = Map[Max[0, #] &, a, {2}]


Bob Hanlon

---- Mayasky <alix.zhang at gmail.com> wrote: 

=============
Suppose there is a N*N matrix.

1. How can I change all elements that satisfy i*j>N to 0 ? (Here i, j
is position of this element, as in mat[[i,j]])

2. How can I change all negative elements in that matrix to 0 ?

I know a "for loop" can be used, I just wonder if there is any more
concise and beautiful ways. (I doubt Mathematica doesn't have a 'find'
function as in another system which conveniently returns indice of elements
that satisfy a certain condition)



  • Prev by Date: Re: exporting coordinate triplets out of
  • Next by Date: Re: Putting an If in my function
  • Previous by thread: Re: Re: Two questions about modification of a
  • Next by thread: Re: Two questions about modification of a matrix.