Search All of the Math Forum:

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

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

 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

On 4/25/14 at 12:44 AM, alan.isaac@gmail.com (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

Date Subject Author
4/20/14 Alan
4/21/14 Bill Rowe
4/25/14 Alan
4/26/14 Bill Rowe