用案例选择 [英] Selecting with Cases
问题描述
请考虑:
Subsets[Flatten[ParallelTable[{i, j}, {i, 1, 96}, {j, 1, 4}], 1], {4}]
我需要选择所有子列表使得i值在每个子列表中从不相同4
I need to select all the Sublist such that the the i value is never the same within each sublist of 4
{{3,1},{4,1},{5,1} {{1,1},{1,2},{2,3},{6,1}}应该被拒绝接受{6,1}}。我的价值1被重复了2次。
{{3,1},{4,1},{5,1},{6,1}} should be accepted while {{1,1},{1,2},{2,3},{6,1}} should be rejected. The Value 1 for i being repeated 2 times.
我知道我可以用Cases来做,但是不要理解它的语法,并找到关于案例的帮助相对于其潜在的应用程序来说,相当空白。
I know I could do this with Cases, but don`t understand the Syntax of it, and find the help on Cases rather empty compared to its potential applications.
推荐答案
假设您的数据位于变量数据
,以下应该这样做:
Assuming your data is in the variable data
, the following should do it:
Select[data, Length@Union[#[[All, 1]]] === 4 &]
这需要 / code> - 值(即第一个元素),并检查4个值是否全部不同(即,如果我们删除重复项,我们仍然有4个)
This takes the "i
"-value (i.e. first element), and checks that the 4 values are all different (i.e. if we remove the duplicates we still have 4 of them)
这篇关于用案例选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!