文章目录(Table of Contents)
Creating a third list from two given lists(通过以给出的两个列表创建第三个列表)
问题
原文链接:https://mathematica.stackexchange.com/questions/155953/creating-a-third-list-from-two-given-lists
原文
I imported 2 lists of the form {{x1,y1}, {x2,y2}, ...}
and {{x1,y'1}, {x2,y'2}, ...}
into Mathematica. I want to make a ListPlot the list {{x1, y1 - y'1}, {x2, y2 - y'2}, ...}
.
How can I create the third list by subtracting only the second column values of the first two lists keeping the first column intact.
翻译
我在mathematica输入了两个形式如下的列表, {{x1,y1}, {x2,y2}, ...}
, {{x1,y'1}, {x2,y'2}, ...}
. 我想要画如下列表的散点图 {{x1, y1 - y'1}, {x2, y2 - y'2}, ...}
.
我应该如何通过减前两个列表的第二列二保持他们第一列不变,来创建第三个列表
高票回答
原文
Another solution is:
p = {{x1, y1}, {x2, y2}}; q = {{x1, Y1}, {x2, Y2}};
p - ({0, 1} # & /@ q)
(* {{x1, y1 - Y1}, {x2, y2 - Y2}} *)
This works by simply replacing the first column of one of the lists with 0 before subtracting.
翻译
另一种解决办法如下:
p = {{x1, y1}, {x2, y2}}; q = {{x1, Y1}, {x2, Y2}};
p - ({0, 1} # & /@ q)
(* {{x1, y1 - Y1}, {x2, y2 - Y2}} *)
其工作原理是用0替换 之前两列数字中一个的第一列,然后再做减法。
还有一种方法如下,使用Associate
a1 = AssociationThread @@ Transpose[d1];
a2 = AssociationThread @@ Transpose[d2];
r = a1 - a2;
一些单词及句子
- intact:完整的,原封不动的
- duplicate:复制的,重复的
- 微信公众号
- 关注微信公众号
- QQ群
- 我们的QQ群号
评论