On Mar 6, 3:08 am, guerom00 <guero... at gmail.com> wrote:
> Right now, I write :
>
> MapAt[2*#&,data,Table[{i,1},{i,1,Length[data]}]]
>
> It's OK but I isn't there another way to achieve this as I find this rather "involved" for such a simple thing ?
Hello,
I also found this problematic, so I made a little helper function:
myMapAt::usage="myMapAt[f,expr,{i,j,\[Ellipsis]}] applies function f
to the parts of expr at positions specified by {i,j,\[Ellipsis]}.
Unlike MapAt, the position specification may include List, Span and
All.";
myMapAt[f_,x_,pos_List] := MapAt[f,x, If[FreeQ[Unique[dummy]@@pos,All|
List|Span], pos, Cases[Array[{##}&,Take[Dimensions[x],Length[pos]]],
List@@Append[(Unique[dummy]@@pos) /. {All->HoldPattern[_],
{ii__}:>Alternatives[ii], Span[ii__]:>Alternatives@@(Range@@({ii}/.All-
>Max[Dimensions[x]]))}, HoldPattern[___]],\[Infinity]]]]
myMapAt[f_,x_,pos_]:=myMapAt[f,x,{pos}]
The usage you want would then be
myMapAt[2 # &, data, {All, 1}]
Hope that helps. Bug reports appreciated.