MathGroup Archive 2014

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

Search the Archive

Re: boolean indexing for subset reassignment

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132616] Re: boolean indexing for subset reassignment
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Mon, 21 Apr 2014 05:12:04 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

On 4/20/14 at 4:47 AM, alan.isaac at gmail.com (Alan) wrote:

>Two years ago this answer was given:
>http://mathematica.stackexchange.com/questions/2821/does-mathematica
>-have-advanced-indexing

>Essentially, the answer was that Mathematica did not provide direct
>support for this feature (unlike say NumPy, R, etc.).  Work arounds
>were suggested.

>Has the situation changed?

No, there is no built-in function that does just what was
described. But this is a very simple thing to do in Mathematica.

generate an array with some values greater than 15:

In[3]:= a = RandomInteger[{1, 20}, {4, 3}]

Out[3]= {{12, 6, 17}, {4, 17, 19}, {14, 10, 7}, {8, 2, 15}}

generate the array to change:

In[4]:= b = RandomReal[1, {4, 3}]

Out[4]= {{0.6304544421081466, 0.10672523812862322,
      0.4822372961689563}, {0.06301096415944252,
      0.975158725702236, 0.052202491707093346},
    {0.06883790695346681, 0.7890506831190796,
      0.8367965617051536}, {0.8641752609839166,
      0.6371442124093818, 0.9217402690944818}}

then

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

Out[5]= {{0.6304544421081466, 0.10672523812862322, 0.},
    {0.06301096415944252, 0., 0.}, {0.06883790695346681,
      0.7890506831190796, 0.8367965617051536},
    {0.8641752609839166, 0.6371442124093818,
      0.9217402690944818}}

is array b changed to have a 0 wherever the corresponding
element of a is greater than 15




  • Prev by Date: Save path bug
  • Next by Date: Re: Save path bug
  • Previous by thread: boolean indexing for subset reassignment
  • Next by thread: Re: boolean indexing for subset reassignment