本文整理汇总了Python中mvpa2.datasets.base.Dataset.select方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.select方法的具体用法?Python Dataset.select怎么用?Python Dataset.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mvpa2.datasets.base.Dataset
的用法示例。
在下文中一共展示了Dataset.select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dataset_select_getitem
# 需要导入模块: from mvpa2.datasets.base import Dataset [as 别名]
# 或者: from mvpa2.datasets.base.Dataset import select [as 别名]
def test_dataset_select_getitem():
ds = Dataset(np.arange(15).reshape((5,-1)),
sa=dict(targets=range(5),
chunks=['a', 'b', 'a', 'b', 'a']),
fa=dict(voxel_indices=[[1, 2], [2, 1], [0, 0]],
roi=['x', 'x', 'z']))
# either sa or fa selection must be provided!
assert_raises(RuntimeError, ds.select)
assert_raises(RuntimeError, ds.select, strict=False)
sd = {'targets': range(3), 'chunks': 'a'}
for ds_ in (ds[sd], ds.select(sd), ds.select(sd, strict=False)):
assert(ds_.shape == (2, 3))
assert_array_equal(ds_.chunks, ['a', 'a'])
fd = {'roi': ['x']}
for ds_ in (ds[sd, fd ], ds.select(sd, fd), ds.select(sd, fd, strict=False)):
assert(ds_.shape == (2, 2))
assert_array_equal(ds_.chunks, ['a', 'a'])
assert_array_equal(ds_.fa.roi, ['x', 'x'])
fd = {'voxel_indices': [[1, 2]]}
for ds_ in (ds[:, fd], ds.select(None, fd), ds.select(fadict=fd), ds.select(fadict=fd, strict=False)):
assert(ds_.shape == (5, 1))
assert_array_equal(ds_.fa.voxel_indices, [[1, 2]])
# select two voxels, but also swap "selection" values out of order.
# result should still be not reordered features
ds_ = ds[{'chunks': ['b']},
{'voxel_indices': [[0, 0], [1, 2]]}]
assert(ds_.shape == (2, 2))
assert_array_equal(ds_.chunks, ['b', 'b'])
assert_array_equal(ds_.fa.voxel_indices, [[1, 2], [0, 0]])
for m in (ds.__getitem__, ds.select):
assert_raises(ValueError, m, {'invalid': [1]})
# we are strict for now, to avoid human typos in specifying which items
# to pick up -- if none was matching -- error!
assert_raises(ValueError, ds.__getitem__, {'targets': ['nonexisting']})
assert_raises(ValueError, ds.__getitem__, {'targets': [0, 999]})
# but allow loose matching with strict=False
ds_ = ds.select({'targets': [0, 999]}, strict=False)
assert_array_equal(ds[{'targets': [0]}].samples, ds_.samples)
assert_true(np.all(ds_.sa.targets == 0))
# Let's just test collection's function directly regarding correct operation
# on difficult cases
voxel_indices = np.array([[[1, 2, 3], [2, 1, 1]],
[[2, 1, 1], [2, 1, 1]],
[[1, 2, 3], [1, 2, 3]],
[[4, 4, 4], [4, 4, 4]],
[[2, 1, 1], [2, 1, 1]],
])
cmp = FeatureAttributesCollection._compare_to_value
for strict in [True, False]:
assert_raises(ValueError, cmp, voxel_indices, [1, 2, 3], strict=strict)
assert_raises(ValueError, cmp, voxel_indices, 4, strict=strict)
assert_raises(ValueError, cmp, voxel_indices, [[1, 2, 3]], strict=strict)
assert_array_equal(cmp(voxel_indices, [[2, 1, 1], [2, 1, 1]]),
[False, True, False, False, True])
# matching compatible elements should puke if not present, unless strict=False
assert_raises(ValueError, cmp, voxel_indices, [[2, 1, 1], [2, 1, 999]])
assert_array_equal(cmp(voxel_indices, [[2, 1, 1], [2, 1, 999]], strict=False),
[False, False, False, False, False])