本文整理汇总了Python中numpy.fromregex方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.fromregex方法的具体用法?Python numpy.fromregex怎么用?Python numpy.fromregex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.fromregex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_record_unicode
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fromregex [as 别名]
def test_record_unicode(self):
utf8 = b'\xcf\x96'
with temppath() as path:
with open(path, 'wb') as f:
f.write(b'1.312 foo' + utf8 + b' \n1.534 bar\n4.444 qux')
dt = [('num', np.float64), ('val', 'U4')]
x = np.fromregex(path, r"(?u)([0-9.]+)\s+(\w+)", dt, encoding='UTF-8')
a = np.array([(1.312, 'foo' + utf8.decode('UTF-8')), (1.534, 'bar'),
(4.444, 'qux')], dtype=dt)
assert_array_equal(x, a)
regexp = re.compile(r"([0-9.]+)\s+(\w+)", re.UNICODE)
x = np.fromregex(path, regexp, dt, encoding='UTF-8')
assert_array_equal(x, a)
#####--------------------------------------------------------------------------
示例2: read_global_mean_surf_area_thickness
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fromregex [as 别名]
def read_global_mean_surf_area_thickness(stats_file):
"""Returns total surface area of white surface, global mean cortical thickness"""
# Snippet from the relevant part of aparc.stats
# Measure Cortex, NumVert, Number of Vertices, 120233, unitless
# Measure Cortex, WhiteSurfArea, White Surface Total Area, 85633.5, mm^2
# Measure Cortex, MeanThickness, Mean Thickness, 2.59632, mm
wb_regex_pattern = r'# Measure Cortex, ([\w/+_\- ]+), ([\w/+_\- ]+), ([\d\.]+),' \
r' ([\w/+_\-^]+)'
wb_aparc_dtype = np.dtype('U100,U100,f8,U10')
# wb_aparc_dtype = [('f0', '<U100'), ('f1', '<U100'), ('f2', '<f8'), ('f3', '<U10')]
wb_stats = np.fromregex(stats_file, wb_regex_pattern, dtype=wb_aparc_dtype)
# concatenating while surf total area and global mean thickness
stats = [wb_stats[1][2], wb_stats[2][2]]
return stats
示例3: test_record
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fromregex [as 别名]
def test_record(self):
c = TextIO()
c.write('1.312 foo\n1.534 bar\n4.444 qux')
c.seek(0)
dt = [('num', np.float64), ('val', 'S3')]
x = np.fromregex(c, r"([0-9.]+)\s+(...)", dt)
a = np.array([(1.312, 'foo'), (1.534, 'bar'), (4.444, 'qux')],
dtype=dt)
assert_array_equal(x, a)
示例4: test_record_2
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fromregex [as 别名]
def test_record_2(self):
c = TextIO()
c.write('1312 foo\n1534 bar\n4444 qux')
c.seek(0)
dt = [('num', np.int32), ('val', 'S3')]
x = np.fromregex(c, r"(\d+)\s+(...)", dt)
a = np.array([(1312, 'foo'), (1534, 'bar'), (4444, 'qux')],
dtype=dt)
assert_array_equal(x, a)
示例5: test_record_3
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fromregex [as 别名]
def test_record_3(self):
c = TextIO()
c.write('1312 foo\n1534 bar\n4444 qux')
c.seek(0)
dt = [('num', np.float64)]
x = np.fromregex(c, r"(\d+)\s+...", dt)
a = np.array([(1312,), (1534,), (4444,)], dtype=dt)
assert_array_equal(x, a)
示例6: test_record_unicode
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fromregex [as 别名]
def test_record_unicode(self):
utf8 = b'\xcf\x96'
with temppath() as path:
with open(path, 'wb') as f:
f.write(b'1.312 foo' + utf8 + b' \n1.534 bar\n4.444 qux')
dt = [('num', np.float64), ('val', 'U4')]
x = np.fromregex(path, r"(?u)([0-9.]+)\s+(\w+)", dt, encoding='UTF-8')
a = np.array([(1.312, 'foo' + utf8.decode('UTF-8')), (1.534, 'bar'),
(4.444, 'qux')], dtype=dt)
assert_array_equal(x, a)
regexp = re.compile(r"([0-9.]+)\s+(\w+)", re.UNICODE)
x = np.fromregex(path, regexp, dt, encoding='UTF-8')
assert_array_equal(x, a)
示例7: test_compiled_bytes
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fromregex [as 别名]
def test_compiled_bytes(self):
regexp = re.compile(b'(\\d)')
c = BytesIO(b'123')
dt = [('num', np.float64)]
a = np.array([1, 2, 3], dtype=dt)
x = np.fromregex(c, regexp, dt)
assert_array_equal(x, a)
#####--------------------------------------------------------------------------
示例8: test_record_3
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import fromregex [as 别名]
def test_record_3(self):
c = TextIO()
c.write('1312 foo\n1534 bar\n4444 qux')
c.seek(0)
dt = [('num', np.float64)]
x = np.fromregex(c, r"(\d+)\s+...", dt)
a = np.array([(1312,), (1534,), (4444,)], dtype=dt)
assert_array_equal(x, a)
#####--------------------------------------------------------------------------