Positioning in a list
up vote
5
down vote
favorite
I have the following list:
l={2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x}
I want to pick those elements that have coefficients bigger than 1, i.e. {2 x, 4 x, 2 x, 4 x, 2 x}
I tried
Select[CoefficientList[{2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x},
x][[All, 2]], # > 1 &]*x
which return what I need but I believe there must be a much shorter and faster way? Also I would like to find the position of {2 x, 4 x, 2 x, 4 x, 2 x}
in my original list so I did:
Position[{2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x}, {2 x, 4 x, 2 x,
4 x, 2 x}]
which does not work so I must be wrong
list-manipulation
add a comment |
up vote
5
down vote
favorite
I have the following list:
l={2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x}
I want to pick those elements that have coefficients bigger than 1, i.e. {2 x, 4 x, 2 x, 4 x, 2 x}
I tried
Select[CoefficientList[{2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x},
x][[All, 2]], # > 1 &]*x
which return what I need but I believe there must be a much shorter and faster way? Also I would like to find the position of {2 x, 4 x, 2 x, 4 x, 2 x}
in my original list so I did:
Position[{2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x}, {2 x, 4 x, 2 x,
4 x, 2 x}]
which does not work so I must be wrong
list-manipulation
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I have the following list:
l={2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x}
I want to pick those elements that have coefficients bigger than 1, i.e. {2 x, 4 x, 2 x, 4 x, 2 x}
I tried
Select[CoefficientList[{2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x},
x][[All, 2]], # > 1 &]*x
which return what I need but I believe there must be a much shorter and faster way? Also I would like to find the position of {2 x, 4 x, 2 x, 4 x, 2 x}
in my original list so I did:
Position[{2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x}, {2 x, 4 x, 2 x,
4 x, 2 x}]
which does not work so I must be wrong
list-manipulation
I have the following list:
l={2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x}
I want to pick those elements that have coefficients bigger than 1, i.e. {2 x, 4 x, 2 x, 4 x, 2 x}
I tried
Select[CoefficientList[{2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x},
x][[All, 2]], # > 1 &]*x
which return what I need but I believe there must be a much shorter and faster way? Also I would like to find the position of {2 x, 4 x, 2 x, 4 x, 2 x}
in my original list so I did:
Position[{2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x}, {2 x, 4 x, 2 x,
4 x, 2 x}]
which does not work so I must be wrong
list-manipulation
list-manipulation
asked yesterday
William
55628
55628
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
up vote
4
down vote
accepted
l = {2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x};
s = Select[CoefficientList[l, x][[All, 2]], # > 1 &]*x
p = Position[l, Alternatives @@ Union[s]]
{{1}, {3}, {6}, {7}, {10}}
Extract[l, p]
add a comment |
up vote
4
down vote
You might do like this:
l /. x -> 1 /. x_ /; x == 1 -> Nothing /. a_ -> a*x
(* {2 x, 4 x, 2 x, 4 x, 2 x} *)
Have fun!
add a comment |
up vote
4
down vote
You can try
Pick[l,Exponent[x,l],0]
{2 x, 4 x, 2 x, 4 x, 2 x}
or
Flatten[Take[l,#]&/@Position[Exponent[x,l],0]]
Also if you want the positions try
Position[Exponent[x, l], 0]
{{1}, {3}, {6}, {7}, {10}}
add a comment |
up vote
3
down vote
l = {2 x, x, 4 x, -x, x, 2 x, 4 x, x, x, 2 x};
test = Clip[Coefficient[l, x], {1, 1}, {1, 0}]; (* 1 means coeffient <= 1, else 0 *)
l2 = Pick[l, test, 0]
pos = Ordering[test, Length[l2]]
{2 x, 4 x, 2 x, 4 x, 2 x}
{1, 3, 6, 7, 10}
add a comment |
up vote
2
down vote
l={2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x};
Pick[l, Unitize[D[l, x] - 1], 1]
{2 x, 4 x, 2 x, 4 x, 2 x}
Flatten@Position[Unitize[D[l, x] - 1], 1]
{1, 3, 6, 7, 10}
add a comment |
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
l = {2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x};
s = Select[CoefficientList[l, x][[All, 2]], # > 1 &]*x
p = Position[l, Alternatives @@ Union[s]]
{{1}, {3}, {6}, {7}, {10}}
Extract[l, p]
add a comment |
up vote
4
down vote
accepted
l = {2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x};
s = Select[CoefficientList[l, x][[All, 2]], # > 1 &]*x
p = Position[l, Alternatives @@ Union[s]]
{{1}, {3}, {6}, {7}, {10}}
Extract[l, p]
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
l = {2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x};
s = Select[CoefficientList[l, x][[All, 2]], # > 1 &]*x
p = Position[l, Alternatives @@ Union[s]]
{{1}, {3}, {6}, {7}, {10}}
Extract[l, p]
l = {2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x};
s = Select[CoefficientList[l, x][[All, 2]], # > 1 &]*x
p = Position[l, Alternatives @@ Union[s]]
{{1}, {3}, {6}, {7}, {10}}
Extract[l, p]
edited yesterday
answered yesterday
Chris Degnen
21.6k23482
21.6k23482
add a comment |
add a comment |
up vote
4
down vote
You might do like this:
l /. x -> 1 /. x_ /; x == 1 -> Nothing /. a_ -> a*x
(* {2 x, 4 x, 2 x, 4 x, 2 x} *)
Have fun!
add a comment |
up vote
4
down vote
You might do like this:
l /. x -> 1 /. x_ /; x == 1 -> Nothing /. a_ -> a*x
(* {2 x, 4 x, 2 x, 4 x, 2 x} *)
Have fun!
add a comment |
up vote
4
down vote
up vote
4
down vote
You might do like this:
l /. x -> 1 /. x_ /; x == 1 -> Nothing /. a_ -> a*x
(* {2 x, 4 x, 2 x, 4 x, 2 x} *)
Have fun!
You might do like this:
l /. x -> 1 /. x_ /; x == 1 -> Nothing /. a_ -> a*x
(* {2 x, 4 x, 2 x, 4 x, 2 x} *)
Have fun!
answered yesterday
Alexei Boulbitch
20.9k2369
20.9k2369
add a comment |
add a comment |
up vote
4
down vote
You can try
Pick[l,Exponent[x,l],0]
{2 x, 4 x, 2 x, 4 x, 2 x}
or
Flatten[Take[l,#]&/@Position[Exponent[x,l],0]]
Also if you want the positions try
Position[Exponent[x, l], 0]
{{1}, {3}, {6}, {7}, {10}}
add a comment |
up vote
4
down vote
You can try
Pick[l,Exponent[x,l],0]
{2 x, 4 x, 2 x, 4 x, 2 x}
or
Flatten[Take[l,#]&/@Position[Exponent[x,l],0]]
Also if you want the positions try
Position[Exponent[x, l], 0]
{{1}, {3}, {6}, {7}, {10}}
add a comment |
up vote
4
down vote
up vote
4
down vote
You can try
Pick[l,Exponent[x,l],0]
{2 x, 4 x, 2 x, 4 x, 2 x}
or
Flatten[Take[l,#]&/@Position[Exponent[x,l],0]]
Also if you want the positions try
Position[Exponent[x, l], 0]
{{1}, {3}, {6}, {7}, {10}}
You can try
Pick[l,Exponent[x,l],0]
{2 x, 4 x, 2 x, 4 x, 2 x}
or
Flatten[Take[l,#]&/@Position[Exponent[x,l],0]]
Also if you want the positions try
Position[Exponent[x, l], 0]
{{1}, {3}, {6}, {7}, {10}}
edited yesterday
answered yesterday
J42161217
2,763218
2,763218
add a comment |
add a comment |
up vote
3
down vote
l = {2 x, x, 4 x, -x, x, 2 x, 4 x, x, x, 2 x};
test = Clip[Coefficient[l, x], {1, 1}, {1, 0}]; (* 1 means coeffient <= 1, else 0 *)
l2 = Pick[l, test, 0]
pos = Ordering[test, Length[l2]]
{2 x, 4 x, 2 x, 4 x, 2 x}
{1, 3, 6, 7, 10}
add a comment |
up vote
3
down vote
l = {2 x, x, 4 x, -x, x, 2 x, 4 x, x, x, 2 x};
test = Clip[Coefficient[l, x], {1, 1}, {1, 0}]; (* 1 means coeffient <= 1, else 0 *)
l2 = Pick[l, test, 0]
pos = Ordering[test, Length[l2]]
{2 x, 4 x, 2 x, 4 x, 2 x}
{1, 3, 6, 7, 10}
add a comment |
up vote
3
down vote
up vote
3
down vote
l = {2 x, x, 4 x, -x, x, 2 x, 4 x, x, x, 2 x};
test = Clip[Coefficient[l, x], {1, 1}, {1, 0}]; (* 1 means coeffient <= 1, else 0 *)
l2 = Pick[l, test, 0]
pos = Ordering[test, Length[l2]]
{2 x, 4 x, 2 x, 4 x, 2 x}
{1, 3, 6, 7, 10}
l = {2 x, x, 4 x, -x, x, 2 x, 4 x, x, x, 2 x};
test = Clip[Coefficient[l, x], {1, 1}, {1, 0}]; (* 1 means coeffient <= 1, else 0 *)
l2 = Pick[l, test, 0]
pos = Ordering[test, Length[l2]]
{2 x, 4 x, 2 x, 4 x, 2 x}
{1, 3, 6, 7, 10}
edited yesterday
answered yesterday
Coolwater
13.9k32351
13.9k32351
add a comment |
add a comment |
up vote
2
down vote
l={2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x};
Pick[l, Unitize[D[l, x] - 1], 1]
{2 x, 4 x, 2 x, 4 x, 2 x}
Flatten@Position[Unitize[D[l, x] - 1], 1]
{1, 3, 6, 7, 10}
add a comment |
up vote
2
down vote
l={2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x};
Pick[l, Unitize[D[l, x] - 1], 1]
{2 x, 4 x, 2 x, 4 x, 2 x}
Flatten@Position[Unitize[D[l, x] - 1], 1]
{1, 3, 6, 7, 10}
add a comment |
up vote
2
down vote
up vote
2
down vote
l={2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x};
Pick[l, Unitize[D[l, x] - 1], 1]
{2 x, 4 x, 2 x, 4 x, 2 x}
Flatten@Position[Unitize[D[l, x] - 1], 1]
{1, 3, 6, 7, 10}
l={2 x, x, 4 x, x, x, 2 x, 4 x, x, x, 2 x};
Pick[l, Unitize[D[l, x] - 1], 1]
{2 x, 4 x, 2 x, 4 x, 2 x}
Flatten@Position[Unitize[D[l, x] - 1], 1]
{1, 3, 6, 7, 10}
answered yesterday
Okkes Dulgerci
3,4611716
3,4611716
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185678%2fpositioning-in-a-list%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password