Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg101081] Re: Two questions about modification of a matrix.
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 23 Jun 2009 07:07:55 -0400 (EDT)
  • References: <h1nevg$8s9$1@smc.vnet.net>

HI,


1)

With[{\[ScriptCapitalN] = 4},
  MapIndexed[If[Times @@ #2 > \[ScriptCapitalN], 0, #1] &, matrix, {2}]
  ]

2)

  Map[If[# < 0, 0, #] &, matrix, {2}]

Regards
   Jens

Mayasky 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: Putting an If in my function
  • Next by Date: Re: from the list select
  • Previous by thread: Re: Two questions about modification of a matrix.
  • Next by thread: Re: Two questions about modification of a matrix.