Creating a third list from two given lists(通过以给出的两个列表创建第三个列表)–[5]

王 茂南 2017年10月5日09:59:07
评论
1825字阅读6分5秒

 

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}} *)

 

Creating a third list from two given lists(通过以给出的两个列表创建第三个列表)–[5]

 

其工作原理是用0替换 之前两列数字中一个的第一列,然后再做减法。

 

Creating a third list from two given lists(通过以给出的两个列表创建第三个列表)–[5]

 

还有一种方法如下,使用Associate

a1 = AssociationThread @@ Transpose[d1];
a2 = AssociationThread @@ Transpose[d2];
r = a1 - a2;

 

Creating a third list from two given lists(通过以给出的两个列表创建第三个列表)–[5]

 

一些单词及句子

  • intact:完整的,原封不动的
  • duplicate:复制的,重复的

 

  • 微信公众号
  • 关注微信公众号
  • weinxin
  • QQ群
  • 我们的QQ群号
  • weinxin
王 茂南
  • 本文由 发表于 2017年10月5日09:59:07
  • 转载请务必保留本文链接:https://mathpretty.com/8238.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: