當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.fromregex方法代碼示例

本文整理匯總了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)


#####-------------------------------------------------------------------------- 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:20,代碼來源:test_io.py

示例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 
開發者ID:raamana,項目名稱:visualqc,代碼行數:19,代碼來源:readers.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_io.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_io.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:test_io.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:17,代碼來源:test_io.py

示例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)

#####-------------------------------------------------------------------------- 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:test_io.py

示例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)


#####-------------------------------------------------------------------------- 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:14,代碼來源:test_io.py


注:本文中的numpy.fromregex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。