當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。