当前位置: 首页>>代码示例>>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;未经允许,请勿转载。