The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: boolean indexing for subset reassignment
Replies: 3   Last Post: Apr 26, 2014 2:07 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bill Rowe

Posts: 1,647
Registered: 3/14/08
Re: boolean indexing for subset reassignment
Posted: Apr 26, 2014 2:07 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 4/25/14 at 12:44 AM, (Alan) wrote:

>Thanks for taking a stab at this, but you have not described
>comparable functionality. Most importantly, you are not changing
>the list `b` in place.

I don't understand why you do not see what I had posted as
comparable since it outputs the same result as described. If
your objection is simply I did not modify the original array,
that is trivial to change. Where I had posted

m = b Unitize@Clip[a, {1, 15}, {0, 0}]

this could be done as:

b = b Unitize@Clip[a, {1, 15}, {0, 0}]

which would change the original array.

In either case, what is returned is an array containing the
elements of b except those that exceed 15 which are replaced
with 0. That is:

In[18]:= a = RandomInteger[{1, 20}, {4, 3}]
Out[18]= {{8, 9, 11}, {16, 7, 20}, {4, 6, 3}, {12, 13, 16}}

In[19]:= b = RandomReal[1, {4, 3}];
b = b Unitize@Clip[a, {1, 15}, {0, 0}];

In[21]:= a Unitize[b]
Out[21]= {{8, 9, 11}, {0, 7, 0}, {4, 6, 3}, {12, 13, 0}}

showing b now has a 0 where a has a value greater than 15

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.