文章目录(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}} *)
![Creating a third list from two given lists(通过以给出的两个列表创建第三个列表)–[5]](https://img.mathpretty.com/snipaste_20170926_133801.png?imageView2/0/q/75|watermark/2/text/5YWz5rOo5YWs5LyX5Y-377ya5paH6Im65pWw5a2m5ZCb/font/5b6u6L2v6ZuF6buR/fontsize/540/fill/IzAwMDAwMA==/dissolve/100/gravity/SouthEast/dx/10/dy/10|imageslim)
其工作原理是用0替换 之前两列数字中一个的第一列,然后再做减法。
![Creating a third list from two given lists(通过以给出的两个列表创建第三个列表)–[5]](https://img.mathpretty.com/snipaste_20170926_133807.png?imageView2/0/q/75|watermark/2/text/5YWz5rOo5YWs5LyX5Y-377ya5paH6Im65pWw5a2m5ZCb/font/5b6u6L2v6ZuF6buR/fontsize/540/fill/IzAwMDAwMA==/dissolve/100/gravity/SouthEast/dx/10/dy/10|imageslim)
还有一种方法如下,使用Associate
a1 = AssociationThread @@ Transpose[d1];
a2 = AssociationThread @@ Transpose[d2];
r = a1 - a2;
![Creating a third list from two given lists(通过以给出的两个列表创建第三个列表)–[5]](https://img.mathpretty.com/snipaste_20170926_133813.png?imageView2/0/q/75|watermark/2/text/5YWz5rOo5YWs5LyX5Y-377ya5paH6Im65pWw5a2m5ZCb/font/5b6u6L2v6ZuF6buR/fontsize/540/fill/IzAwMDAwMA==/dissolve/100/gravity/SouthEast/dx/10/dy/10|imageslim)
一些单词及句子
- intact:完整的,原封不动的
- duplicate:复制的,重复的
- 微信公众号
- 关注微信公众号
-
- QQ群
- 我们的QQ群号
-

![Add 1 to diagonal elements of a matrix(矩阵的对角元素加1)--[4]](https://img.mathpretty.com/20210911_162011_tcryqxk.jpg)
![omit a pairing of numbers from two data ranges in a table(从table产生的两组数中忽略一些数据范围)--[2]](https://img.mathpretty.com/20210911_162041_2wlslen.jpg)
![Geolocate multiple IP addresses(获取大量IP地址的地理位置)--[1]](https://img.mathpretty.com/20210911_162117_jmo0vhq.jpg)

评论