在Mathematica中添加第三列数据 [英] Adding a Third column of data in Mathematica

查看:71
本文介绍了在Mathematica中添加第三列数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的数据表,例如:

I have a very large table of data something like:

lista = {{2,8},{3,4},{5,2}..}

我想将x添加到每个元素中

I would like to add x to every element so it would be

lista ={{x,2,8},{x,3,4},{x,5,2}.....}

在我看来,这似乎应该是微不足道的,但我一直无法找到解决方案.

This seems to me like it should be rather trivial but I have not been able to find a solution.

我将不胜感激.

推荐答案

这几乎是追加到表格将0附加到子列表上的精确重复项问.这些线程中提供了更多带有定时的方法,但是这里有两个很好的方法可以开始:

This is very nearly a duplicate of Appending to the rows of a table and an exact duplicate of Prepend 0 to sublists on the dedicated site where your question should have been asked. Many more methods, with timings, are provided in those threads but here are two good methods to start with:

lista = {{2, 8}, {3, 4}, {5, 2}};

ArrayPad[lista, {{0, 0}, {1, 0}}]

{{0, 2, 8}, {0, 3, 4}, {0, 5, 2}}

或者:

ArrayFlatten @ {{0, lista}}

{{0, 2, 8}, {0, 3, 4}, {0, 5, 2}}


StackExchange专用站点:


Dedicated StackExchange site:

这篇关于在Mathematica中添加第三列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆