Re: Mapping to a specific column or row in a matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg103173] Re: Mapping to a specific column or row in a matrix
- From: dr DanW <dmaxwarren at gmail.com>
- Date: Thu, 10 Sep 2009 07:16:49 -0400 (EDT)
- References: <h7qem5$us$1@smc.vnet.net>
You are correct that you need a combination of Map and MapAt. Specifically, you need the position spec from MapAt with the level spec from Map. MapAtLevel[f_, expr_, n_, levelspec_: {1}] := Map[MapAt[f, #, n] &, expr, levelspec - 1] It looks like you did this, but called it clunky. By creating a new function, it becomes much less clunky. I often have to plot data from a list of {x,y} pairs, but I want to transform all the y values to decibel: dat = {{1, 200.}, {2, 250.}, {3, 300.}}; In[30]:= MapAtLevel[20 Log[10, #] &, dat, 2, 2] Out[30]= {{1, 46.0206}, {2, 47.9588}, {3, 49.5424}} Daniel