MathGroup Archive 2012

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

Search the Archive

Re: Map onto a column

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125512] Re: Map onto a column
  • From: dr DanW <dmaxwarren at gmail.com>
  • Date: Fri, 16 Mar 2012 06:34:02 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jjmv20$cfr$1@smc.vnet.net>

MapAt needs a level specification.  I posted this a few years ago, but here it is again:

MapAtLevel::usage = "MapAtLevel[\!\(\*
StyleBox[\"f\", \"TI\"]\),\!\(\*
StyleBox[\"expr\", \"TI\"]\),\!\(\*
StyleBox[\"n\", \"TI\"]\),\!\(\*
StyleBox[\"levelspec\", \"TI\"]\)] applies \!\(\*
StyleBox[\"f\", \"TI\"]\) to the element at position \!\(\*
StyleBox[\"n\", \"TI\"]\) at level \!\(\*
StyleBox[\"levelspec\", \"TI\"]\) in \!\(\*
StyleBox[\"expr\", \"TI\"]\)."

MapAtLevel[f_, expr_, n_, levelspec_: {1}] := 
 Map[MapAt[f, #, n] &, expr, levelspec - 1] 

I have this in a package of useful utilities I load in my init.m.

A typical use is when I want to plot data on a Decibel scale:

data = Table[{i, 10^(10.*(i/20))}, {i, 5}];
ListPlot[MapAtLevel[20*Log10[#1] & , data, 2, {2}], Joined -> True]

Enjoy,
Daniel



  • Prev by Date: Symbolic tensor analysis in Mathematica 8
  • Next by Date: Running Mathematica via ssh connection.... Very strange results
  • Previous by thread: Re: Map onto a column
  • Next by thread: More "standard" output form