Groups | Search | Server Info | Login | Register
Groups > comp.soft-sys.math.mathematica > #16834
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!newspump.sol.net!post2.nntp.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail |
|---|---|
| From | Bill Rowe <readnews@sbcglobal.net> |
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: boolean indexing for subset reassignment |
| Date | Mon, 21 Apr 2014 09:12:05 +0000 (UTC) |
| Sender | steve@smc.vnet.net |
| Approved | Steven M. Christensen <steve@smc.vnet.net>, Moderator |
| Message-ID | <lj2nd5$6hs$1@smc.vnet.net> (permalink) |
| Lines | 46 |
| Organization | Time-Warner Telecom |
| NNTP-Posting-Date | 21 Apr 2014 09:18:12 GMT |
| NNTP-Posting-Host | 00516bb2.news.twtelecom.net |
| X-Trace | DXC=aQ[CD]llnf;2=0o6GZ=PX5C_A=>8kQj6=;[h;PUXBgb4\BjXfi;a<@9EFiONJ7[Go6Fi;L3mj91[= |
| X-Complaints-To | abuse@twtelecom.net |
| X-Received-Bytes | 2179 |
| X-Received-Body-CRC | 4075449380 |
| Xref | csiph.com comp.soft-sys.math.mathematica:16834 |
Show key headers only | View raw
On 4/20/14 at 4:47 AM, alan.isaac@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
Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar
Re: boolean indexing for subset reassignment Bill Rowe <readnews@sbcglobal.net> - 2014-04-21 09:12 +0000 Re: boolean indexing for subset reassignment Alan <alan.isaac@gmail.com> - 2014-04-25 04:44 +0000
csiph-web