manipulate list in mathematica with select

有些话、适合烂在心里 提交于 2020-01-04 04:13:26

问题


I have imported some data into Mathematica. The data will look similar to

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

I want to throw out all elements for which the x-values are smaller than a given value or create a new list that contains the data for which the x-values are larger than this value. I assume that Select should do the job but I don't know how.

Thanks in advance for the help.


回答1:


How about

 data = {{0,2},{2,3},{4,3},{5,4},{8,4}};
 filtered = Select[data, First[#]>3&];

where you replace 3 with your given value?




回答2:


Another versatile approach is to use Cases and attach a condition (/;)

For example:

data = {{0, 2}, {2, 3}, {4, 3}, {5, 4}, {8, 4}}; Cases[data, {x_, y_} /; x > 3]

or attach a condition as follows (for example):

Cases[data, {x_ /; x > 3, _}]

(The approach will also work with DeleteCases)



来源:https://stackoverflow.com/questions/4118474/manipulate-list-in-mathematica-with-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!