Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8392 > unrolled thread
| Started by | jediwhelan <jediwhelan@googlemail.com> |
|---|---|
| First post | 2012-02-08 10:30 +0000 |
| Last post | 2012-02-09 10:50 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Simply but handy question jediwhelan <jediwhelan@googlemail.com> - 2012-02-08 10:30 +0000
Re: Simply but handy question David Reiss <dbreiss@gmail.com> - 2012-02-09 10:41 +0000
Re: Simply but handy question Peter Breitfeld <phbrf@t-online.de> - 2012-02-09 10:50 +0000
| From | jediwhelan <jediwhelan@googlemail.com> |
|---|---|
| Date | 2012-02-08 10:30 +0000 |
| Subject | Simply but handy question |
| Message-ID | <jgtist$6bb$1@smc.vnet.net> |
Dear group members,
I am new to mathematica (well, I'm not actually but I haven't used it
in 5 years +).
Is there an easy way to return a matrix X of 1's and 0's to test
whether the entries in Y
are different from zero.
i.e.,
if Y = {{a,b},{0,c}}
Then X would return
X = {{1,1},{0,1}}
This would be handy for very large or complicated matrices where one
would like to know if specific entries are zero?
Many thanks,
Paul
[toc] | [next] | [standalone]
| From | David Reiss <dbreiss@gmail.com> |
|---|---|
| Date | 2012-02-09 10:41 +0000 |
| Message-ID | <jh07sm$hvi$1@smc.vnet.net> |
| In reply to | #8392 |
I'm sure you will get many suggestions here. Here is one possibility:
In[31]:= Y = {{a, b}, {0, c}}
Out[31]= {{a, b}, {0, c}}
In[32]:= testValue[0 | 0.] = 0
Out[32]= 0
In[33]:= testValue[_] = 1
Out[33]= 1
In[34]:= Map[testValue, Y, {2}]
Out[34]= {{1, 1}, {0, 1}}
But the key thing that you need to analyze with this and the list of
other ways of approaching this problem is which works the most
efficiently for the class of problems you want to apply it to.
--David
On Feb 8, 5:30 am, jediwhelan <jediwhe...@googlemail.com> wrote:
> Dear group members,
>
> I am new to mathematica (well, I'm not actually but I haven't used it
> in 5 years +).
>
> Is there an easy way to return a matrix X of 1's and 0's to test
> whether the entries in Y
> are different from zero.
>
> i.e.,
>
> if Y = {{a,b},{0,c}}
>
> Then X would return
>
> X = {{1,1},{0,1}}
>
> This would be handy for very large or complicated matrices where one
> would like to know if specific entries are zero?
>
> Many thanks,
> Paul
[toc] | [prev] | [next] | [standalone]
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Date | 2012-02-09 10:50 +0000 |
| Message-ID | <jh08d0$i7c$1@smc.vnet.net> |
| In reply to | #8392 |
Maybe like this:
SetAttributes[myUnitize,Listable]
maUnitize[x_]:=If[x==0,0,1,1]
In: myUnitize[Y]
Out: {{1, 1}, {0, 1}}
jediwhelan wrote:
> Dear group members,
>
> I am new to mathematica (well, I'm not actually but I haven't used it
> in 5 years +).
>
> Is there an easy way to return a matrix X of 1's and 0's to test
> whether the entries in Y
> are different from zero.
>
> i.e.,
>
> if Y = {{a,b},{0,c}}
>
> Then X would return
>
> X = {{1,1},{0,1}}
>
> This would be handy for very large or complicated matrices where one
> would like to know if specific entries are zero?
>
> Many thanks,
> Paul
>
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web