本文整理汇总了Python中idtxl.data.Data._get_data_slice方法的典型用法代码示例。如果您正苦于以下问题:Python Data._get_data_slice方法的具体用法?Python Data._get_data_slice怎么用?Python Data._get_data_slice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类idtxl.data.Data
的用法示例。
在下文中一共展示了Data._get_data_slice方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_data_type
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import _get_data_slice [as 别名]
def test_data_type():
"""Test if data class always returns the correct data type."""
# Change data type for the same object instance.
d_int = np.random.randint(0, 10, size=(3, 50))
orig_type = type(d_int[0][0])
data = Data(d_int, dim_order='ps', normalise=False)
# The concrete type depends on the platform:
# https://mail.scipy.org/pipermail/numpy-discussion/2011-November/059261.html
# Hence, compare against the type automatically assigned by Python or
# against np.integer
assert data.data_type is orig_type, 'Data type did not change.'
assert issubclass(type(data.data[0, 0, 0]), np.integer), (
'Data type is not an int.')
d_float = np.random.randn(3, 50)
data.set_data(d_float, dim_order='ps')
assert data.data_type is np.float64, 'Data type did not change.'
assert issubclass(type(data.data[0, 0, 0]), np.float), (
'Data type is not a float.')
# Check if data returned by the object have the correct type.
d_int = np.random.randint(0, 10, size=(3, 50, 5))
data = Data(d_int, dim_order='psr', normalise=False)
real = data.get_realisations((0, 5), [(1, 1), (1, 3)])[0]
assert issubclass(type(real[0, 0]), np.integer), (
'Realisations type is not an int.')
sl = data._get_data_slice(0)[0]
assert issubclass(type(sl[0, 0]), np.integer), (
'Data slice type is not an int.')
settings = {'perm_type': 'random'}
sl_perm = data.slice_permute_samples(0, settings)[0]
assert issubclass(type(sl_perm[0, 0]), np.integer), (
'Permuted data slice type is not an int.')
samples = data.permute_samples((0, 5), [(1, 1), (1, 3)], settings)[0]
assert issubclass(type(samples[0, 0]), np.integer), (
'Permuted samples type is not an int.')
示例2: test_get_data_slice
# 需要导入模块: from idtxl.data import Data [as 别名]
# 或者: from idtxl.data.Data import _get_data_slice [as 别名]
def test_get_data_slice():
n = 10
n_replications = 3
d = Data(np.vstack((np.zeros(n).astype(int),
np.ones(n).astype(int),
2 * np.ones(n).astype(int))),
'rs', normalise=False)
[s, i] = d._get_data_slice(process=0, offset_samples=0, shuffle=False)
# test unshuffled slicing
for r in range(n_replications):
assert s[0][r] == i[r], 'Replication index {0} is not correct.'.format(
r)
# test shuffled slicing
[s, i] = d._get_data_slice(process=0, offset_samples=0, shuffle=True)
for r in range(n_replications):
assert s[0][r] == i[r], 'Replication index {0} is not correct.'.format(
r)
offset = 3
d = Data(np.arange(n), 's', normalise=False)
[s, i] = d._get_data_slice(process=0, offset_samples=offset, shuffle=False)
assert s.shape[0] == (n - offset), 'Offset not handled correctly.'