Let's have a list:
d={0.00144444, 17.6365, 6.68574, 22.5808, -1.85266, -11.1622, 100.021, 1.}
I want to replace some parts of it by zeroes:
Documentation of ReplacePart
says:
ReplacePart[expr,{i,j,…}->new]
replaces the part at position {i,j,…}
.
but
ReplacePart[d, {1, 4, 5, 6, 7} -> 0.0]
produces
{0.00144444, 17.6365, 6.68574, 22.5808, -1.85266, -11.1622, 100.021, 1.}
and to make things stranger
ReplacePart[d, {{1}, 4, 5, 6, 7} -> 0.0]
{0., 17.6365, 6.68574, 0., 0., 0., 0., 1.}
but
ReplacePart[d, {1, {4}, 5, 6, 7} -> 0.0]
During evaluation of ReplacePart::pkspec1: The expression {4} cannot be used as a part specification.
(* {0.00144444, 17.6365, 6.68574, 22.5808, -1.85266, -11.1622, \
100.021, 1.} *)
Is this a bug? What is the proper syntax for ReplacePart
in my situation?
ReplacePart[data[[1, 1]], {{1}, {4}, {5}, {6}, {7}} -> 0.0]
rather thanReplacePart[data[[1, 1]], {1, 4, 5, 6, 7} -> 0.0]
?ReplacePart[data[[1, 1]], {{1}, 4, 5, 6, 7} -> 0.0]
is weird, though. $\endgroup$ – march Aug 28 '17 at 17:57data[[1,1]] = d
effectively. $\endgroup$ – leosenko Aug 28 '17 at 18:01[[i,j,...]]
?{i,j,..}
specifies a list, not a position, no? $\endgroup$ – leosenko Aug 28 '17 at 18:07Position
docs because[[]]
is fromPart
. $\endgroup$ – Kuba♦ Aug 28 '17 at 18:08