Assaignment.py - import tables import numpy as np filename...

This preview shows page 1 - 3 out of 6 pages.

The preview shows page 1 - 3 out of 6 pages.
import tablesimport numpy as npfilename = 'dist.dat'ROW_SIZE = 100NUM_COLUMNS = 200f = tables.open_file(filename, mode='w')atom = tables.Float64Atom()array_c = f.create_earray(f.root, 'data', atom, (0, ROW_SIZE))for idx in range(NUM_COLUMNS):x = np.random.rand(1, ROW_SIZE)array_c.append(x)f.close()f = tables.open_file(filename, mode='a')f.root.data.append(x)f = tables.open_file(filename, mode='r')print(f.root.data[1:10,2:20])from pathlib import Pathimport numpy as npimport osp = Path('temp.npy')with p.open('ab') as f:np.save(f, np.zeros(2))np.save(f, np.ones(2))with p.open('rb') as f:fsz = os.fstat(f.fileno()).st_sizeout = np.load(f)while f.tell() < fsz:out = np.vstack((out, np.load(f)))import numpy as npimport numpy.lib.format as fmtdef get_header(fnames):dtype = Noneshape_0 = 0shape_1 = Nonefor i, fname in enumerate(fnames):m = np.load(fname, mmap_mode='r')if i == 0:dtype = m.dtypeshape_1 = m.shape[1]else:assert m.dtype == dtypeassert m.shape[1] == shape_1shape_0 += m.shape[0]return {'descr': fmt.dtype_to_descr(dtype), 'fortran_order': False, 'shape':(shape_0, shape_1)}
def concatenate(res_fname, input_fnames):header = get_header(input_fnames)with open(res_fname, 'wb') as f:fmt.write_array_header_2_0(f, header)for fname in input_fnames:m = np.load(fname)f.write(m.tostring('C'))from npy_append_array import NpyAppendArrayimport numpy as nparr1 = np.array([[1,2],[3,4]])arr2 = np.array([[1,2],[3,4],[5,6]])filename='out.npy'np.save(filename, arr1)

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 6 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
NoProfessor
Tags
Computer file, Returning, fsz

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture