当前位置: 首页>>代码示例>>Python>>正文


Python compat.Path方法代码示例

本文整理汇总了Python中numpy.compat.Path方法的典型用法代码示例。如果您正苦于以下问题:Python compat.Path方法的具体用法?Python compat.Path怎么用?Python compat.Path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.compat的用法示例。


在下文中一共展示了compat.Path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_multifield_view

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_multifield_view(self):
        a = np.ones(1, dtype=[('x', 'i4'), ('y', 'i4'), ('z', 'f4')])
        v = a[['x', 'z']]
        with temppath(suffix='.npy') as path:
            path = Path(path)
            np.save(path, v)
            data = np.load(path)
            assert_array_equal(data, v) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_io.py

示例2: test_loadtxt

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_loadtxt(self):
        with temppath(suffix='.txt') as path:
            path = Path(path)
            a = np.array([[1.1, 2], [3, 4]])
            np.savetxt(path, a)
            x = np.loadtxt(path)
            assert_array_equal(x, a) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_io.py

示例3: test_save_load

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_save_load(self):
        # Test that pathlib.Path instances can be used with save.
        with temppath(suffix='.npy') as path:
            path = Path(path)
            a = np.array([[1, 2], [3, 4]], int)
            np.save(path, a)
            data = np.load(path)
            assert_array_equal(data, a) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_io.py

示例4: test_save_load_memmap

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_save_load_memmap(self):
        # Test that pathlib.Path instances can be loaded mem-mapped.
        with temppath(suffix='.npy') as path:
            path = Path(path)
            a = np.array([[1, 2], [3, 4]], int)
            np.save(path, a)
            data = np.load(path, mmap_mode='r')
            assert_array_equal(data, a)
            # close the mem-mapped file
            del data 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_io.py

示例5: test_save_load_memmap_readwrite

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_save_load_memmap_readwrite(self):
        # Test that pathlib.Path instances can be written mem-mapped.
        with temppath(suffix='.npy') as path:
            path = Path(path)
            a = np.array([[1, 2], [3, 4]], int)
            np.save(path, a)
            b = np.load(path, mmap_mode='r+')
            a[0][0] = 5
            b[0][0] = 5
            del b  # closes the file
            data = np.load(path)
            assert_array_equal(data, a) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_io.py

示例6: test_savez_compressed_load

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_savez_compressed_load(self):
        # Test that pathlib.Path instances can be used with savez.
        with temppath(suffix='.npz') as path:
            path = Path(path)
            np.savez_compressed(path, lab='place holder')
            data = np.load(path)
            assert_array_equal(data['lab'], 'place holder')
            data.close() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_io.py

示例7: test_genfromtxt

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_genfromtxt(self):
        with temppath(suffix='.txt') as path:
            path = Path(path)
            a = np.array([(1, 2), (3, 4)])
            np.savetxt(path, a)
            data = np.genfromtxt(path)
            assert_array_equal(a, data) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_io.py

示例8: test_ndfromtxt

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_ndfromtxt(self):
        # Test outputting a standard ndarray
        with temppath(suffix='.txt') as path:
            path = Path(path)
            with path.open('w') as f:
                f.write(u'1 2\n3 4')

            control = np.array([[1, 2], [3, 4]], dtype=int)
            test = np.ndfromtxt(path, dtype=int)
            assert_array_equal(test, control) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_io.py

示例9: test_mafromtxt

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [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

示例10: test_recfromtxt

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_recfromtxt(self):
        with temppath(suffix='.txt') as path:
            path = Path(path)
            with path.open('w') as f:
                f.write(u'A,B\n0,1\n2,3')

            kwargs = dict(delimiter=",", missing_values="N/A", names=True)
            test = np.recfromtxt(path, **kwargs)
            control = np.array([(0, 1), (2, 3)],
                               dtype=[('A', int), ('B', int)])
            assert_(isinstance(test, np.recarray))
            assert_equal(test, control) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_io.py

示例11: test_tofile_fromfile

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_tofile_fromfile(self):
        with temppath(suffix='.bin') as path:
            path = Path(path)
            np.random.seed(123)
            a = np.random.rand(10).astype('f8,i4,a5')
            a[5] = (0.5,10,'abcde')
            with path.open("wb") as fd:
                a.tofile(fd)
            x = np.core.records.fromfile(path,
                                         formats='f8,i4,a5',
                                         shape=10)
            assert_array_equal(x, a) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_records.py

示例12: test_save_load

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_save_load(self):
        # Test that pathlib.Path instances can be used with savez.
        with temppath(suffix='.npy') as path:
            path = Path(path)
            a = np.array([[1, 2], [3, 4]], int)
            np.save(path, a)
            data = np.load(path)
            assert_array_equal(data, a) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:10,代码来源:test_io.py

示例13: test_savez_load

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_savez_load(self):
        # Test that pathlib.Path instances can be used with savez.
        with temppath(suffix='.npz') as path:
            path = Path(path)
            np.savez(path, lab='place holder')
            with np.load(path) as data:
                assert_array_equal(data['lab'], 'place holder') 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:9,代码来源:test_io.py

示例14: test_recfromtxt

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_recfromtxt(self):
        with temppath(suffix='.txt') as path:
            path = Path(path)
            with path.open('w') as f:
                f.write(u'A,B\n0,1\n2,3')

            kwargs = dict(delimiter=",", missing_values="N/A", names=True)
            test = np.recfromtxt(path, **kwargs)
            control = np.array([(0, 1), (2, 3)],
                               dtype=[('A', np.int), ('B', np.int)])
            self.assertTrue(isinstance(test, np.recarray))
            assert_equal(test, control) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:14,代码来源:test_io.py

示例15: test_recfromcsv

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import Path [as 别名]
def test_recfromcsv(self):
        with temppath(suffix='.txt') as path:
            path = Path(path)
            with path.open('w') as f:
                f.write(u'A,B\n0,1\n2,3')

            kwargs = dict(missing_values="N/A", names=True, case_sensitive=True)
            test = np.recfromcsv(path, dtype=None, **kwargs)
            control = np.array([(0, 1), (2, 3)],
                               dtype=[('A', np.int), ('B', np.int)])
            self.assertTrue(isinstance(test, np.recarray))
            assert_equal(test, control) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:14,代码来源:test_io.py


注:本文中的numpy.compat.Path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。