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


Python numpy.mafromtxt方法代碼示例

本文整理匯總了Python中numpy.mafromtxt方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.mafromtxt方法的具體用法?Python numpy.mafromtxt怎麽用?Python numpy.mafromtxt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.mafromtxt方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_withmissing

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import mafromtxt [as 別名]
def test_withmissing(self):
        data = TextIO('A,B\n0,1\n2,N/A')
        kwargs = dict(delimiter=",", missing_values="N/A", names=True)
        test = np.mafromtxt(data, dtype=None, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', int), ('B', int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        #
        data.seek(0)
        test = np.mafromtxt(data, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', float), ('B', float)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_io.py

示例2: test_withmissing

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import mafromtxt [as 別名]
def test_withmissing(self):
        data = TextIO('A,B\n0,1\n2,N/A')
        kwargs = dict(delimiter=",", missing_values="N/A", names=True)
        test = np.mafromtxt(data, dtype=None, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.int), ('B', np.int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        #
        data.seek(0)
        test = np.mafromtxt(data, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.float), ('B', np.float)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:19,代碼來源:test_io.py

示例3: test_fancy_dtype_alt

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import mafromtxt [as 別名]
def test_fancy_dtype_alt(self):
        # Check that a nested dtype isn't MIA
        data = TextIO('1,2,3.0\n4,5,6.0\n')
        fancydtype = np.dtype([('x', int), ('y', [('t', int), ('s', float)])])
        test = np.mafromtxt(data, dtype=fancydtype, delimiter=',')
        control = ma.array([(1, (2, 3.0)), (4, (5, 6.0))], dtype=fancydtype)
        assert_equal(test, control) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_io.py

示例4: test_user_missing_values

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import mafromtxt [as 別名]
def test_user_missing_values(self):
        data = "A, B, C\n0, 0., 0j\n1, N/A, 1j\n-9, 2.2, N/A\n3, -99, 3j"
        basekwargs = dict(dtype=None, delimiter=",", names=True,)
        mdtype = [('A', int), ('B', float), ('C', complex)]
        #
        test = np.mafromtxt(TextIO(data), missing_values="N/A",
                            **basekwargs)
        control = ma.array([(0, 0.0, 0j), (1, -999, 1j),
                            (-9, 2.2, -999j), (3, -99, 3j)],
                           mask=[(0, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, 0)],
                           dtype=mdtype)
        assert_equal(test, control)
        #
        basekwargs['dtype'] = mdtype
        test = np.mafromtxt(TextIO(data),
                            missing_values={0: -9, 1: -99, 2: -999j}, **basekwargs)
        control = ma.array([(0, 0.0, 0j), (1, -999, 1j),
                            (-9, 2.2, -999j), (3, -99, 3j)],
                           mask=[(0, 0, 0), (0, 1, 0), (1, 0, 1), (0, 1, 0)],
                           dtype=mdtype)
        assert_equal(test, control)
        #
        test = np.mafromtxt(TextIO(data),
                            missing_values={0: -9, 'B': -99, 'C': -999j},
                            **basekwargs)
        control = ma.array([(0, 0.0, 0j), (1, -999, 1j),
                            (-9, 2.2, -999j), (3, -99, 3j)],
                           mask=[(0, 0, 0), (0, 1, 0), (1, 0, 1), (0, 1, 0)],
                           dtype=mdtype)
        assert_equal(test, control) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:32,代碼來源:test_io.py

示例5: test_withmissing_float

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import mafromtxt [as 別名]
def test_withmissing_float(self):
        data = TextIO('A,B\n0,1.5\n2,-999.00')
        test = np.mafromtxt(data, dtype=None, delimiter=',',
                            missing_values='-999.0', names=True,)
        control = ma.array([(0, 1.5), (2, -1.)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', int), ('B', float)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:test_io.py

示例6: test_mafromtxt

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import mafromtxt [as 別名]
def test_mafromtxt(self):
        # From `test_fancy_dtype_alt` above
        with temppath(suffix='.txt') as path:
            path = Path(path)
            with path.open('w') as f:
                f.write(u'1,2,3.0\n4,5,6.0\n')

            test = np.mafromtxt(path, delimiter=',')
            control = ma.array([(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)])
            assert_equal(test, control) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_io.py

示例7: test_withmissing_float

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import mafromtxt [as 別名]
def test_withmissing_float(self):
        data = TextIO('A,B\n0,1.5\n2,-999.00')
        test = np.mafromtxt(data, dtype=None, delimiter=',',
                            missing_values='-999.0', names=True,)
        control = ma.array([(0, 1.5), (2, -1.)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.int), ('B', np.float)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:11,代碼來源:test_io.py


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