List manipulation: conditional result based on variable-length sublistsSelect rows of matrix that are higher...
Closest Proximity of Oceans to Freshwater Springs
What prevents a US state from colonizing a smaller state?
How can combining souls together not increase its volume?
Could you fall off a planet if it was being accelerated by engines?
My colleague is constantly blaming me for his errors
How to securely dispose of a smartphone?
80's-90's TV show or movie about life clocks
List Manipulation : {{{a,b},{c,d}},{{e,f},{g,h}}} into {{a,b},{c,d},{e,f},{g,h}}
List manipulation: conditional result based on variable-length sublists
Are Valenar elves and Aereni elves different races of elves?
Bin Packing with Relational Penalization
The Lucas argument vs the theorem-provers--who wins and why?
Undetectable mail tracker
What was the point of separating stdout and stderr?
Word ending in "-ine" for rat-like
What happens if a caster is surprised while casting a spell with a long casting time?
I just started should I accept a farewell lunch for a coworker I don't know?
How can I deal with extreme temperatures in a hotel room?
When casting a spell with a long casting time, what happens if you don't spend your action on a turn to continue casting?
How do I present a future free of gender stereotypes without being jarring or overpowering the narrative?
Is ALTER TABLE ... DROP COLUMN really a metadata only operation?
Adjective for 'made of pus' or 'corrupted by pus' or something of something of pus
If two black hole event horizons overlap (touch) can they ever separate again?
If I were to build a J3 cub twice the size of the original using the same CG would it fly?
List manipulation: conditional result based on variable-length sublists
Select rows of matrix that are higher than a given rowSplitting a list into increasing sublistsGroup list by rules in sequence using DateDifference and TotalPartition list into $n$ sublistsListing all distinct exhaustive combinations of sublists of a certain lengthRemove the right sublistlist manipulation by ruleSort a list in a descending orderSpecific list manipulationSelect list elements based on other list
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$begingroup$
Suppose I have the following lists:
eqexp={a,b,c,d}
eqval={e,f,g,h}
signval={{},{1},{-1},{1,-1}}
I want to create a new list of inequalities, where the signval list signals whether to use greater than or less than. I need it to handle empty sublists, and multi-component sublists. My desired output is:
{{},{b>f},{c<g},{d>h,d<h}}
All lists have the same number of top-level elements. eqexp and eqval are one-dimensional. signval is two-dimensional, but the length of the sub-lists is variable. The only numerical values allowed in signval are 1 and -1.
How do I do this?
list-manipulation
$endgroup$
add a comment |
$begingroup$
Suppose I have the following lists:
eqexp={a,b,c,d}
eqval={e,f,g,h}
signval={{},{1},{-1},{1,-1}}
I want to create a new list of inequalities, where the signval list signals whether to use greater than or less than. I need it to handle empty sublists, and multi-component sublists. My desired output is:
{{},{b>f},{c<g},{d>h,d<h}}
All lists have the same number of top-level elements. eqexp and eqval are one-dimensional. signval is two-dimensional, but the length of the sub-lists is variable. The only numerical values allowed in signval are 1 and -1.
How do I do this?
list-manipulation
$endgroup$
add a comment |
$begingroup$
Suppose I have the following lists:
eqexp={a,b,c,d}
eqval={e,f,g,h}
signval={{},{1},{-1},{1,-1}}
I want to create a new list of inequalities, where the signval list signals whether to use greater than or less than. I need it to handle empty sublists, and multi-component sublists. My desired output is:
{{},{b>f},{c<g},{d>h,d<h}}
All lists have the same number of top-level elements. eqexp and eqval are one-dimensional. signval is two-dimensional, but the length of the sub-lists is variable. The only numerical values allowed in signval are 1 and -1.
How do I do this?
list-manipulation
$endgroup$
Suppose I have the following lists:
eqexp={a,b,c,d}
eqval={e,f,g,h}
signval={{},{1},{-1},{1,-1}}
I want to create a new list of inequalities, where the signval list signals whether to use greater than or less than. I need it to handle empty sublists, and multi-component sublists. My desired output is:
{{},{b>f},{c<g},{d>h,d<h}}
All lists have the same number of top-level elements. eqexp and eqval are one-dimensional. signval is two-dimensional, but the length of the sub-lists is variable. The only numerical values allowed in signval are 1 and -1.
How do I do this?
list-manipulation
list-manipulation
edited 10 hours ago
user64494
4,1242 gold badges14 silver badges23 bronze badges
4,1242 gold badges14 silver badges23 bronze badges
asked 10 hours ago
Kevin AusmanKevin Ausman
8152 silver badges15 bronze badges
8152 silver badges15 bronze badges
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
$begingroup$
MapThread[#3 /. {1 -> #1 > #2, -1 -> #1 < #2} &, {eqexp, eqval, signval}]
(* {{}, {b > f}, {c < g}, {d > h, d < h}} *)
$endgroup$
$begingroup$
Nice! I'm embarrassed that I didn't come up with that. Thank you!
$endgroup$
– Kevin Ausman
10 hours ago
add a comment |
$begingroup$
And the power of posting... I have found a way to do it:
MapThread[
Function[{a, b, c}, If[c > 0, a > b, a < b], Listable],
{eqexp, eqval, signval}]
If there is a better way to do it, I would love to see it, though!
$endgroup$
add a comment |
$begingroup$
MapThread[Through @ # @ ##2 &, {signval /. {1 -> Greater, -1 -> Less}, eqexp, eqval}]
{{}, {b > f}, {c < g}, {d > h, d < h}}
Alternatively, define a function f
with attribute Listable
and use regular function application:
f0 = Function[, # @ ##2, Listable];
f0[signval /. {1 -> Greater, -1 -> Less}, eqexp, eqval]
{{}, {b > f}, {c < g}, {d > h, d < h}}
$endgroup$
add a comment |
$begingroup$
Which[
#1 === {}, {},
#1 === {1}, {#2 > #3},
#1 === {-1}, {#2 < #3},
#1 === {1, -1},
{#2 > #3, #2 < #3}]&
@@@ Transpose[{signval, eqexp, eqval}]
(* {{},{b>f},{c<g},{d>h,d<h}} *)
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201123%2flist-manipulation-conditional-result-based-on-variable-length-sublists%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
MapThread[#3 /. {1 -> #1 > #2, -1 -> #1 < #2} &, {eqexp, eqval, signval}]
(* {{}, {b > f}, {c < g}, {d > h, d < h}} *)
$endgroup$
$begingroup$
Nice! I'm embarrassed that I didn't come up with that. Thank you!
$endgroup$
– Kevin Ausman
10 hours ago
add a comment |
$begingroup$
MapThread[#3 /. {1 -> #1 > #2, -1 -> #1 < #2} &, {eqexp, eqval, signval}]
(* {{}, {b > f}, {c < g}, {d > h, d < h}} *)
$endgroup$
$begingroup$
Nice! I'm embarrassed that I didn't come up with that. Thank you!
$endgroup$
– Kevin Ausman
10 hours ago
add a comment |
$begingroup$
MapThread[#3 /. {1 -> #1 > #2, -1 -> #1 < #2} &, {eqexp, eqval, signval}]
(* {{}, {b > f}, {c < g}, {d > h, d < h}} *)
$endgroup$
MapThread[#3 /. {1 -> #1 > #2, -1 -> #1 < #2} &, {eqexp, eqval, signval}]
(* {{}, {b > f}, {c < g}, {d > h, d < h}} *)
answered 10 hours ago
RomanRoman
12k1 gold badge19 silver badges46 bronze badges
12k1 gold badge19 silver badges46 bronze badges
$begingroup$
Nice! I'm embarrassed that I didn't come up with that. Thank you!
$endgroup$
– Kevin Ausman
10 hours ago
add a comment |
$begingroup$
Nice! I'm embarrassed that I didn't come up with that. Thank you!
$endgroup$
– Kevin Ausman
10 hours ago
$begingroup$
Nice! I'm embarrassed that I didn't come up with that. Thank you!
$endgroup$
– Kevin Ausman
10 hours ago
$begingroup$
Nice! I'm embarrassed that I didn't come up with that. Thank you!
$endgroup$
– Kevin Ausman
10 hours ago
add a comment |
$begingroup$
And the power of posting... I have found a way to do it:
MapThread[
Function[{a, b, c}, If[c > 0, a > b, a < b], Listable],
{eqexp, eqval, signval}]
If there is a better way to do it, I would love to see it, though!
$endgroup$
add a comment |
$begingroup$
And the power of posting... I have found a way to do it:
MapThread[
Function[{a, b, c}, If[c > 0, a > b, a < b], Listable],
{eqexp, eqval, signval}]
If there is a better way to do it, I would love to see it, though!
$endgroup$
add a comment |
$begingroup$
And the power of posting... I have found a way to do it:
MapThread[
Function[{a, b, c}, If[c > 0, a > b, a < b], Listable],
{eqexp, eqval, signval}]
If there is a better way to do it, I would love to see it, though!
$endgroup$
And the power of posting... I have found a way to do it:
MapThread[
Function[{a, b, c}, If[c > 0, a > b, a < b], Listable],
{eqexp, eqval, signval}]
If there is a better way to do it, I would love to see it, though!
answered 10 hours ago
Kevin AusmanKevin Ausman
8152 silver badges15 bronze badges
8152 silver badges15 bronze badges
add a comment |
add a comment |
$begingroup$
MapThread[Through @ # @ ##2 &, {signval /. {1 -> Greater, -1 -> Less}, eqexp, eqval}]
{{}, {b > f}, {c < g}, {d > h, d < h}}
Alternatively, define a function f
with attribute Listable
and use regular function application:
f0 = Function[, # @ ##2, Listable];
f0[signval /. {1 -> Greater, -1 -> Less}, eqexp, eqval]
{{}, {b > f}, {c < g}, {d > h, d < h}}
$endgroup$
add a comment |
$begingroup$
MapThread[Through @ # @ ##2 &, {signval /. {1 -> Greater, -1 -> Less}, eqexp, eqval}]
{{}, {b > f}, {c < g}, {d > h, d < h}}
Alternatively, define a function f
with attribute Listable
and use regular function application:
f0 = Function[, # @ ##2, Listable];
f0[signval /. {1 -> Greater, -1 -> Less}, eqexp, eqval]
{{}, {b > f}, {c < g}, {d > h, d < h}}
$endgroup$
add a comment |
$begingroup$
MapThread[Through @ # @ ##2 &, {signval /. {1 -> Greater, -1 -> Less}, eqexp, eqval}]
{{}, {b > f}, {c < g}, {d > h, d < h}}
Alternatively, define a function f
with attribute Listable
and use regular function application:
f0 = Function[, # @ ##2, Listable];
f0[signval /. {1 -> Greater, -1 -> Less}, eqexp, eqval]
{{}, {b > f}, {c < g}, {d > h, d < h}}
$endgroup$
MapThread[Through @ # @ ##2 &, {signval /. {1 -> Greater, -1 -> Less}, eqexp, eqval}]
{{}, {b > f}, {c < g}, {d > h, d < h}}
Alternatively, define a function f
with attribute Listable
and use regular function application:
f0 = Function[, # @ ##2, Listable];
f0[signval /. {1 -> Greater, -1 -> Less}, eqexp, eqval]
{{}, {b > f}, {c < g}, {d > h, d < h}}
edited 29 mins ago
answered 3 hours ago
kglrkglr
201k10 gold badges230 silver badges458 bronze badges
201k10 gold badges230 silver badges458 bronze badges
add a comment |
add a comment |
$begingroup$
Which[
#1 === {}, {},
#1 === {1}, {#2 > #3},
#1 === {-1}, {#2 < #3},
#1 === {1, -1},
{#2 > #3, #2 < #3}]&
@@@ Transpose[{signval, eqexp, eqval}]
(* {{},{b>f},{c<g},{d>h,d<h}} *)
$endgroup$
add a comment |
$begingroup$
Which[
#1 === {}, {},
#1 === {1}, {#2 > #3},
#1 === {-1}, {#2 < #3},
#1 === {1, -1},
{#2 > #3, #2 < #3}]&
@@@ Transpose[{signval, eqexp, eqval}]
(* {{},{b>f},{c<g},{d>h,d<h}} *)
$endgroup$
add a comment |
$begingroup$
Which[
#1 === {}, {},
#1 === {1}, {#2 > #3},
#1 === {-1}, {#2 < #3},
#1 === {1, -1},
{#2 > #3, #2 < #3}]&
@@@ Transpose[{signval, eqexp, eqval}]
(* {{},{b>f},{c<g},{d>h,d<h}} *)
$endgroup$
Which[
#1 === {}, {},
#1 === {1}, {#2 > #3},
#1 === {-1}, {#2 < #3},
#1 === {1, -1},
{#2 > #3, #2 < #3}]&
@@@ Transpose[{signval, eqexp, eqval}]
(* {{},{b>f},{c<g},{d>h,d<h}} *)
edited 4 hours ago
m_goldberg
90.6k8 gold badges75 silver badges203 bronze badges
90.6k8 gold badges75 silver badges203 bronze badges
answered 8 hours ago
user1066user1066
6,3982 gold badges20 silver badges33 bronze badges
6,3982 gold badges20 silver badges33 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201123%2flist-manipulation-conditional-result-based-on-variable-length-sublists%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown