v]c@`s)ddlmZmZmZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m ZddlZddlmZddlmZddlmZddlmZmZdd lmZdd lmZdd lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)dd l*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3dd l4m5Z5ej6ddkrddl7m8Z8n ddl9m:Z:ddl;m8Z8eddZ<dddddddddddddd d!d"gZ=ej>ej?d#dZ?d$e@fd%YZAd&ZBd'e8fd(YZCedeDeEeFd)d*ZGeDeDd+ZHe?eHeFeFd,ZId-ZJe?eJd.ZKd/ZLe?eLd0ZMeFeDd1ZNd2ZOd3ZPedeQd4eDeDdeDeEdd5eDd6 ZReDeDeDeDeDeDeDd7ZSe?eSd8d9d:d;d;d<eDd=ZTedeDd>ZUedeQd4eDddeDeDeDeDeDeDeDd?eEeFd@eDeEeFeFeDd5dAZVdBZWdCZXdDZYdEZZdS(Fi(tdivisiontabsolute_importtprint_functionN(t itemgettertindexi(tformat(t DataSource(t overrides(tpackbitst unpackbits(t set_module(t recursive( t LineSplittert NameValidatortStringConvertertConverterErrortConverterLockErrortConversionWarningt_is_string_likethas_nested_fieldst flatten_dtypet easy_dtypet _decode_line( tasbytestasstrt asunicodetasbytes_nestedtbytest basestringtunicodet os_fspatht os_PathLike(tpicklei(tMapping(tmaptnumpycO`s&tjdtddtj||S(Ns0np.loads is deprecated, use pickle.loads insteadt stackleveli(twarningstwarntDeprecationWarningR tloads(targstkwargs((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR(&s tsavetxttloadtxtt genfromtxtt ndfromtxtt mafromtxtt recfromtxtt recfromcsvtloadR(tsavetsaveztsavez_compressedRR t fromregexRtmoduletBagObjcB`s)eZdZdZdZdZRS(su BagObj(obj) Convert attribute look-ups to getitems on the object passed in. Parameters ---------- obj : class instance Object on which attribute look-up is performed. Examples -------- >>> from numpy.lib.npyio import BagObj as BO >>> class BagDemo(object): ... def __getitem__(self, key): # An instance of BagObj(BagDemo) ... # will call this method when any ... # attribute look-up is required ... result = "Doesn't matter what you want, " ... return result + "you're gonna get this" ... >>> demo_obj = BagDemo() >>> bagobj = BO(demo_obj) >>> bagobj.hello_there "Doesn't matter what you want, you're gonna get this" >>> bagobj.I_can_be_anything "Doesn't matter what you want, you're gonna get this" cC`stj||_dS(N(tweakreftproxyt_obj(tselftobj((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt__init__XscC`s<ytj|d|SWntk r7t|nXdS(NR;(tobjectt__getattribute__tKeyErrortAttributeError(R<tkey((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR@\s cC`sttj|djS(s Enables dir(bagobj) to list the files in an NpzFile. This also enables tab-completion in an interpreter or IPython. R;(tlistR?R@tkeys(R<((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt__dir__bs(t__name__t __module__t__doc__R>R@RF(((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR8:s  cO`sGt|dst|}nddl}t|d<|j|||S(s Create a ZipFile. Allows for Zip64, and the `file` argument can accept file, str, or pathlib.Path objects. `args` and `kwargs` are passed to the zipfile.ZipFile constructor. treadiNt allowZip64(thasattrRtzipfiletTruetZipFile(tfileR)R*RM((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pytzipfile_factoryks   tNpzFilecB`seZdZeed dZdZdZdZdZ dZ dZ dZ e jjd krd Zd ZnRS( sf NpzFile(fid) A dictionary-like object with lazy-loading of files in the zipped archive provided on construction. `NpzFile` is used to load files in the NumPy ``.npz`` data archive format. It assumes that files in the archive have a ``.npy`` extension, other files are ignored. The arrays and file strings are lazily loaded on either getitem access using ``obj['key']`` or attribute lookup using ``obj.f.key``. A list of all files (without ``.npy`` extensions) can be obtained with ``obj.files`` and the ZipFile object itself using ``obj.zip``. Attributes ---------- files : list of str List of all files in the archive with a ``.npy`` extension. zip : ZipFile instance The ZipFile object initialized with the zipped archive. f : BagObj instance An object on which attribute can be performed as an alternative to getitem access on the `NpzFile` instance itself. allow_pickle : bool, optional Allow loading pickled data. Default: False .. versionchanged:: 1.16.3 Made default False in response to CVE-2019-6446. pickle_kwargs : dict, optional Additional keyword arguments to pass on to pickle.load. These are only useful when loading object arrays saved on Python 2 when using Python 3. Parameters ---------- fid : file or str The zipped archive to open. This is either a file-like object or a string containing the path to the archive. own_fid : bool, optional Whether NpzFile should close the file handle. Requires that `fid` is a file-like object. Examples -------- >>> from tempfile import TemporaryFile >>> outfile = TemporaryFile() >>> x = np.arange(10) >>> y = np.sin(x) >>> np.savez(outfile, x=x, y=y) >>> outfile.seek(0) >>> npz = np.load(outfile) >>> isinstance(npz, np.lib.io.NpzFile) True >>> npz.files ['y', 'x'] >>> npz['x'] # getitem access array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> npz.f.x # attribute lookup array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) cC`st|}|j|_g|_||_||_xG|jD]<}|jdrl|jj|d q@|jj|q@W||_t ||_ |r||_ n d|_ dS(Ns.npyi( RQtnamelistt_filestfilest allow_picklet pickle_kwargstendswithtappendtzipR8tftfidtNone(R<R\town_fidRVRWt_ziptx((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR>s      cC`s|S(N((R<((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt __enter__scC`s|jdS(N(tclose(R<texc_typet exc_valuet traceback((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt__exit__scC`s]|jdk r(|jjd|_n|jdk rP|jjd|_nd|_dS(s" Close the file. N(RZR]RbR\R[(R<((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyRbs    cC`s|jdS(N(Rb(R<((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt__del__scC`s t|jS(N(titerRU(R<((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt__iter__scC`s t|jS(N(tlenRU(R<((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt__len__scC`st}||jkrt}n"||jkr@t}|d7}n|r|jj|}|jttj }|j |tj kr|jj|}tj |d|j d|j S|jj|Sntd|dS(Ns.npyRVRWs%s is not a file in the archive(tFalseRTRNRURZtopenRJRjRt MAGIC_PREFIXRbt read_arrayRVRWRA(R<RCtmemberRtmagic((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt __getitem__s"       icC`s tjdtdd|jS(NsiNpzFile.iteritems is deprecated in python 3, to match the removal of dict.itertems. Use .items() instead.R$i(R%R&R'titems(R<((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt iteritemss cC`s tjdtdd|jS(NsgNpzFile.iterkeys is deprecated in python 3, to match the removal of dict.iterkeys. Use .keys() instead.R$i(R%R&R'RE(R<((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pytiterkeyss N(RGRHRIRlR]R>RaRfRbRgRiRkRrtsyst version_infotmajorRtRu(((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyRRzsA        tASCIIc C`s|dkrtdntjddkrFtd|d|}ni}t|d rj|}t}ntt|d }t}z+d }d } t t j } |j | } |j t| t |  d | j|s| j| rt|d|d|d|} t}| S| t j kr\|r@t j|d|St j|d|d|SnS|sqtdnytj||SWn'tk rtdt|nXWd|r|jnXdS(s# Load arrays or pickled objects from ``.npy``, ``.npz`` or pickled files. Parameters ---------- file : file-like object, string, or pathlib.Path The file to read. File-like objects must support the ``seek()`` and ``read()`` methods. Pickled files require that the file-like object support the ``readline()`` method as well. mmap_mode : {None, 'r+', 'r', 'w+', 'c'}, optional If not None, then memory-map the file, using the given mode (see `numpy.memmap` for a detailed description of the modes). A memory-mapped array is kept on disk. However, it can be accessed and sliced like any ndarray. Memory mapping is especially useful for accessing small fragments of large files without reading the entire file into memory. allow_pickle : bool, optional Allow loading pickled object arrays stored in npy files. Reasons for disallowing pickles include security, as loading pickled data can execute arbitrary code. If pickles are disallowed, loading object arrays will fail. Default: False .. versionchanged:: 1.16.3 Made default False in response to CVE-2019-6446. fix_imports : bool, optional Only useful when loading Python 2 generated pickled files on Python 3, which includes npy/npz files containing object arrays. If `fix_imports` is True, pickle will try to map the old Python 2 names to the new names used in Python 3. encoding : str, optional What encoding to use when reading Python 2 strings. Only useful when loading Python 2 generated pickled files in Python 3, which includes npy/npz files containing object arrays. Values other than 'latin1', 'ASCII', and 'bytes' are not allowed, as they can corrupt numerical data. Default: 'ASCII' Returns ------- result : array, tuple, dict, etc. Data stored in the file. For ``.npz`` files, the returned instance of NpzFile class must be closed to avoid leaking file descriptors. Raises ------ IOError If the input file does not exist or cannot be read. ValueError The file contains an object array, but allow_pickle=False given. See Also -------- save, savez, savez_compressed, loadtxt memmap : Create a memory-map to an array stored in a file on disk. lib.format.open_memmap : Create or load a memory-mapped ``.npy`` file. Notes ----- - If the file contains pickle data, then whatever object is stored in the pickle is returned. - If the file is a ``.npy`` file, then a single array is returned. - If the file is a ``.npz`` file, then a dictionary-like object is returned, containing ``{filename: array}`` key-value pairs, one for each file in the archive. - If the file is a ``.npz`` file, the returned value supports the context manager protocol in a similar fashion to the open function:: with load('foo.npz') as data: a = data['a'] The underlying file descriptor is closed when exiting the 'with' block. Examples -------- Store data to disk, and load it again: >>> np.save('/tmp/123', np.array([[1, 2, 3], [4, 5, 6]])) >>> np.load('/tmp/123.npy') array([[1, 2, 3], [4, 5, 6]]) Store compressed data to disk, and load it again: >>> a=np.array([[1, 2, 3], [4, 5, 6]]) >>> b=np.array([1, 2]) >>> np.savez('/tmp/123.npz', a=a, b=b) >>> data = np.load('/tmp/123.npz') >>> data['a'] array([[1, 2, 3], [4, 5, 6]]) >>> data['b'] array([1, 2]) >>> data.close() Mem-map the stored array, and then access the second row directly from disk: >>> X = np.load('/tmp/123.npy', mmap_mode='r') >>> X[1, :] memmap([4, 5, 6]) Rytlatin1Rs.encoding must be 'ASCII', 'latin1', or 'bytes'iitencodingt fix_importsRJtrbsPKsPKiR^RVRWtmodes@Cannot load file containing pickled data when allow_pickle=Falses'Failed to interpret file %s as a pickleN(RyRzR(t ValueErrorRvRwtdictRLRlRmRRNRjRRnRJtseektmint startswithRRt open_memmapRoR R2t ExceptiontIOErrortreprRb( RPt mmap_modeRVR|R{RWR\R^t _ZIP_PREFIXt _ZIP_SUFFIXtNRqtret((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR2#sFj      cC`s|fS(N((RPtarrRVR|((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt_save_dispatcherscC`st}t|dr|}n=t|}|jdsF|d}nt|d}t}tjddkrtd|}nd }z/t j |}t j ||d|d|Wd |r|jnXd S( s Save an array to a binary file in NumPy ``.npy`` format. Parameters ---------- file : file, str, or pathlib.Path File or filename to which the data is saved. If file is a file-object, then the filename is unchanged. If file is a string or Path, a ``.npy`` extension will be appended to the file name if it does not already have one. arr : array_like Array data to be saved. allow_pickle : bool, optional Allow saving object arrays using Python pickles. Reasons for disallowing pickles include security (loading pickled data can execute arbitrary code) and portability (pickled objects may not be loadable on different Python installations, for example if the stored objects require libraries that are not available, and not all pickled data is compatible between Python 2 and Python 3). Default: True fix_imports : bool, optional Only useful in forcing objects in object arrays on Python 3 to be pickled in a Python 2 compatible way. If `fix_imports` is True, pickle will try to map the new Python 3 names to the old module names used in Python 2, so that the pickle data stream is readable with Python 2. See Also -------- savez : Save several arrays into a ``.npz`` archive savetxt, load Notes ----- For a description of the ``.npy`` format, see :py:mod:`numpy.lib.format`. Examples -------- >>> from tempfile import TemporaryFile >>> outfile = TemporaryFile() >>> x = np.arange(10) >>> np.save(outfile, x) >>> outfile.seek(0) # Only needed here to simulate closing & reopening file >>> np.load(outfile) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) RJs.npytwbiiR|RVRWN(RlRLRRXRmRNRvRwRR]tnpt asanyarrayRt write_arrayRb(RPRRVR|R^R\RW((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR3s"2    co`s6x|D] }|VqWx|jD] }|Vq#WdS(N(tvalues(RPR)tkwdstatv((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt_savez_dispatchers  cO`st|||tdS(sa Save several arrays into a single file in uncompressed ``.npz`` format. If arguments are passed in with no keywords, the corresponding variable names, in the ``.npz`` file, are 'arr_0', 'arr_1', etc. If keyword arguments are given, the corresponding variable names, in the ``.npz`` file will match the keyword names. Parameters ---------- file : str or file Either the file name (string) or an open file (file-like object) where the data will be saved. If file is a string or a Path, the ``.npz`` extension will be appended to the file name if it is not already there. args : Arguments, optional Arrays to save to the file. Since it is not possible for Python to know the names of the arrays outside `savez`, the arrays will be saved with names "arr_0", "arr_1", and so on. These arguments can be any expression. kwds : Keyword arguments, optional Arrays to save to the file. Arrays will be saved in the file with the keyword names. Returns ------- None See Also -------- save : Save a single array to a binary file in NumPy format. savetxt : Save an array to a file as plain text. savez_compressed : Save several arrays into a compressed ``.npz`` archive Notes ----- The ``.npz`` file format is a zipped archive of files named after the variables they contain. The archive is not compressed and each file in the archive contains one variable in ``.npy`` format. For a description of the ``.npy`` format, see :py:mod:`numpy.lib.format`. When opening the saved ``.npz`` file with `load` a `NpzFile` object is returned. This is a dictionary-like object which can be queried for its list of arrays (with the ``.files`` attribute), and for the arrays themselves. Examples -------- >>> from tempfile import TemporaryFile >>> outfile = TemporaryFile() >>> x = np.arange(10) >>> y = np.sin(x) Using `savez` with \*args, the arrays are saved with default names. >>> np.savez(outfile, x, y) >>> outfile.seek(0) # Only needed here to simulate closing & reopening file >>> npzfile = np.load(outfile) >>> npzfile.files ['arr_1', 'arr_0'] >>> npzfile['arr_0'] array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) Using `savez` with \**kwds, the arrays are saved with the keyword names. >>> outfile = TemporaryFile() >>> np.savez(outfile, x=x, y=y) >>> outfile.seek(0) >>> npzfile = np.load(outfile) >>> npzfile.files ['y', 'x'] >>> npzfile['x'] array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) N(t_savezRl(RPR)R((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR4%sMco`s6x|D] }|VqWx|jD] }|Vq#WdS(N(R(RPR)RRR((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt_savez_compressed_dispatcherus  cO`st|||tdS(s Save several arrays into a single file in compressed ``.npz`` format. If keyword arguments are given, then filenames are taken from the keywords. If arguments are passed in with no keywords, then stored file names are arr_0, arr_1, etc. Parameters ---------- file : str or file Either the file name (string) or an open file (file-like object) where the data will be saved. If file is a string or a Path, the ``.npz`` extension will be appended to the file name if it is not already there. args : Arguments, optional Arrays to save to the file. Since it is not possible for Python to know the names of the arrays outside `savez`, the arrays will be saved with names "arr_0", "arr_1", and so on. These arguments can be any expression. kwds : Keyword arguments, optional Arrays to save to the file. Arrays will be saved in the file with the keyword names. Returns ------- None See Also -------- numpy.save : Save a single array to a binary file in NumPy format. numpy.savetxt : Save an array to a file as plain text. numpy.savez : Save several arrays into an uncompressed ``.npz`` file format numpy.load : Load the files created by savez_compressed. Notes ----- The ``.npz`` file format is a zipped archive of files named after the variables they contain. The archive is compressed with ``zipfile.ZIP_DEFLATED`` and each file in the archive contains one variable in ``.npy`` format. For a description of the ``.npy`` format, see :py:mod:`numpy.lib.format`. When opening the saved ``.npz`` file with `load` a `NpzFile` object is returned. This is a dictionary-like object which can be queried for its list of arrays (with the ``.files`` attribute), and for the arrays themselves. Examples -------- >>> test_array = np.random.rand(3, 2) >>> test_vector = np.random.rand(4) >>> np.savez_compressed('/tmp/123', a=test_array, b=test_vector) >>> loaded = np.load('/tmp/123.npz') >>> print(np.array_equal(test_array, loaded['a'])) True >>> print(np.array_equal(test_vector, loaded['b'])) True N(RRN(RPR)R((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR5|s>c C`sddl}t|dsFt|}|jdsF|d}qFn|}xSt|D]E\}} d|} | |jkrtd| n| || tcS`stt|S(N(RR(R`((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyRRcS`stt|jddS(Ns+-t-(tcomplexRtreplace(R`((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyRRN(ttypet issubclassRtbool_tuint64tint64tintegert longdoubletfloatingRtbytes_Rtunicode_RR(tdtypeRttyp((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt_getconvs*  iPt#Rc ! `swd k rwtttfr-gngD]} t| ^q4dDtjdj nd k rtn} dkrd t} nt } d k rIyt }Wnt k rg}nXxK|D]C}yt |Wqt k r;}dt |f|_qXqW|nt }yt|trpt|}nt|rtjjj|ddtddtt}nt|t|ddWnt k rtdnXd k rn'd kr<d d l}|jntd }td   fd  f d}ztj|}t|}xt D]}tqWd }y)x"|st }qWWn4t k r@dg}t!j"d|ddnXt#pM|||\} t#|dkrg|D]}t|^q~n=gtD] }|^qdkrt$fg nx| pij%D]\}}r(yj&|}Wq(tk r$qq(Xn| r_d}d d l'}|j(|d||>> from io import StringIO # StringIO behaves like a file object >>> c = StringIO(u"0 1\n2 3") >>> np.loadtxt(c) array([[ 0., 1.], [ 2., 3.]]) >>> d = StringIO(u"M 21 72\nF 35 58") >>> np.loadtxt(d, dtype={'names': ('gender', 'age', 'weight'), ... 'formats': ('S1', 'i4', 'f4')}) array([('M', 21, 72.0), ('F', 35, 58.0)], dtype=[('gender', '|S1'), ('age', '>> c = StringIO(u"1,0,2\n3,0,4") >>> x, y = np.loadtxt(c, delimiter=',', usecols=(0, 2), unpack=True) >>> x array([ 1., 3.]) >>> y array([ 2., 4.]) cs`s|]}tj|VqdS(N(tretescape(t.0tcomment((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pys st|Rs\usecols must be an int or a sequence of ints but it contains at least one element of type %strtR{Rzs1fname must be a string, file handle, or generatoriNc S`sc|jdkr|j}t|dkr:|jgdfS|dtfg}t|dkrx@|jdddD]%}||dd||fg}qvWn|jgttj|j|fSng}g}x{|jD]p}|j |\}}||\} } |j | |j dkr8|j | q|j t| | fqW||fSdS(s;Unpack a structured data-type, and produce re-packing info.iiiiN( tnamesR]tshapeRjtbaseRDRRtprodtfieldstextendtndimRY( R<tdtRtpackingtdimttypestfieldttpRtflat_dtt flat_packing((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pytflatten_dtype_internals& &) cS`s|dkr|dS|tkr*t|S|tkr@t|Sd}g}x?|D]7\}}|j|||||!|||7}qSWt|SdS(s6Pack items into nested lists based on re-packing info.iN(R]ttupleRDRY(R<RsRtstartRtlengtht subpacking((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt pack_itemss     !c`sdt|d}dk r:j|ddd}n|jd}|r\|jSgSdS(s2Chop off comments, strip, and split at delimiter. R{tmaxsplitiis N(RR]Rtstrip(tline(tcommentst delimiterR{tregex_comments(s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt split_lines  c 3`sCg}tjg}tj|}xt|D]\}}|}t|dkrjq:n rg D]}||^qw}nt|kr|d}td|ngt|D]\}} || ^q} | } |j| t||kr:|Vg}q:q:W|r?|VndS(sParse each line, including the first. The file read, `fh`, is a global defined above. Parameters ---------- chunk_size : int At most `chunk_size` lines are read at a time, with iteration until all lines are read. iis"Wrong number of columns at line %dN(t itertoolstchaintisliceRRjRRZRY( t chunk_sizetXt line_iterRRtvalstjtline_numtconvRRs( Rt converterstfht first_linetmax_rowsRRtskiprowsRtusecols(s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt read_datas*    .  Rsloadtxt: Empty input file: "%s"R$iicS`s/t|tkr||S||jdS(NRz(RRtencode(R`R((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt tobytes_firstds Rc`s |jS(N(R(R`(t fencoding(s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyRnRtrefcheck.iis"Illegal value of ndmin keyword: %s(ii(ii(iii(4R]t isinstanceRRRRtcompiletjoinRNRlRDt TypeErrortopindexRR)RRRRtlibt _datasourceRmtgetattrRhRtlocaletgetpreferredencodingR RRtrangetnextt StopIterationR%R&RjRRsRt functoolstpartialt_loadtxt_chunksizetarrayRtresizeRbRtsqueezet atleast_1dt atleast_2dtTR(!RRRRRRRtunpacktndminR{RR`tuser_converterstbyte_converterstusecols_as_listtcol_idxtetfownRRRtdefconvRt first_valst dtype_typesRRRRRtnshapetposR((RRRRR{RRRRRRRRRRs_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR,#st                     *&    "     1   "     c C`s|fS(N(( RRtfmtRtnewlinetheadertfooterRR{((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt_savetxt_dispatcherss%.18et s Rs# c C`srt|trt|}nt|}dtfdY} t} t|trdt|}nt|rt|dj t j j j|dd|} t } tjddkr| | |pd} qn3t|dr| ||pd} n td zOt j|}|jdks8|jdkrNtd |jn^|jd kr|jjdkrt j|j}d } qt|jj} n |jd } t j|} t|ttfkrt|| krtd t |nt|j!t"t|}nt|t r|j#d }td|}|d kr| ryd||fg| }n |g| }|j!|}q| r|d| kr|q| r|| kr|q|}ntd|ft|dkr/|j$dd|}| j%|||n| rx|D]j}g}x.|D]&}|j&|j'|j&|j(qOW|t||}| j%|j$ddq<Wnixf|D]^}y|t||}Wn0t)k rt)dt |j|fnX| j%|qWt|dkrV|j$dd|}| j%|||nWd| rm| j nXdS(s Save an array to a text file. Parameters ---------- fname : filename or file handle If the filename ends in ``.gz``, the file is automatically saved in compressed gzip format. `loadtxt` understands gzipped files transparently. X : 1D or 2D array_like Data to be saved to a text file. fmt : str or sequence of strs, optional A single format (%10.5f), a sequence of formats, or a multi-format string, e.g. 'Iteration %d -- %10.5f', in which case `delimiter` is ignored. For complex `X`, the legal options for `fmt` are: * a single specifier, `fmt='%.4e'`, resulting in numbers formatted like `' (%s+%sj)' % (fmt, fmt)` * a full string specifying every real and imaginary part, e.g. `' %.4e %+.4ej %.4e %+.4ej %.4e %+.4ej'` for 3 columns * a list of specifiers, one per column - in this case, the real and imaginary part must have separate specifiers, e.g. `['%.3e + %.3ej', '(%.15e%+.15ej)']` for 2 columns delimiter : str, optional String or character separating columns. newline : str, optional String or character separating lines. .. versionadded:: 1.5.0 header : str, optional String that will be written at the beginning of the file. .. versionadded:: 1.7.0 footer : str, optional String that will be written at the end of the file. .. versionadded:: 1.7.0 comments : str, optional String that will be prepended to the ``header`` and ``footer`` strings, to mark them as comments. Default: '# ', as expected by e.g. ``numpy.loadtxt``. .. versionadded:: 1.7.0 encoding : {None, str}, optional Encoding used to encode the outputfile. Does not apply to output streams. If the encoding is something other than 'bytes' or 'latin1' you will not be able to load the file in NumPy versions < 1.14. Default is 'latin1'. .. versionadded:: 1.14.0 See Also -------- save : Save an array to a binary file in NumPy ``.npy`` format savez : Save several arrays into an uncompressed ``.npz`` archive savez_compressed : Save several arrays into a compressed ``.npz`` archive Notes ----- Further explanation of the `fmt` parameter (``%[flag]width[.precision]specifier``): flags: ``-`` : left justify ``+`` : Forces to precede result with + or -. ``0`` : Left pad the number with zeros instead of space (see width). width: Minimum number of characters to be printed. The value is not truncated if it has more characters. precision: - For integer specifiers (eg. ``d,i,o,x``), the minimum number of digits. - For ``e, E`` and ``f`` specifiers, the number of digits to print after the decimal point. - For ``g`` and ``G``, the maximum number of significant digits. - For ``s``, the maximum number of characters. specifiers: ``c`` : character ``d`` or ``i`` : signed decimal integer ``e`` or ``E`` : scientific notation with ``e`` or ``E``. ``f`` : decimal floating point ``g,G`` : use the shorter of ``e,E`` or ``f`` ``o`` : signed octal ``s`` : string of characters ``u`` : unsigned decimal integer ``x,X`` : unsigned hexadecimal integer This explanation of ``fmt`` is not complete, for an exhaustive specification see [1]_. References ---------- .. [1] `Format Specification Mini-Language `_, Python Documentation. Examples -------- >>> x = y = z = np.arange(0.0,5.0,1.0) >>> np.savetxt('test.out', x, delimiter=',') # X is an array >>> np.savetxt('test.out', (x,y,z)) # x,y,z equal sized 1D arrays >>> np.savetxt('test.out', x, fmt='%1.4e') # use exponential notation t WriteWrapcB`sDeZdZdZdZdZdZdZdZRS(sEConvert to unicode in py2 or to bytes on bytestream inputs. cS`s"||_||_|j|_dS(N(RR{t first_writetdo_write(R<RR{((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR>-s  cS`s|jjdS(N(RRb(R<((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyRb2scS`s|j|dS(N(R4(R<R((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR5scS`sBt|tr"|jj|n|jj|j|jdS(N(R RRRRR{(R<R((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt write_bytes8scS`s|jjt|dS(N(RRR(R<R((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyt write_normal>scS`sNy|j||j|_Wn*tk rI|j||j|_nXdS(N(R6RR R5(R<R((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR3As    ( RGRHRIR>RbRR5R6R3(((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR2)s     twtR{iiRzRs%fname must be a string or file handles.Expected 1D or 2D array, got %dD array insteadisfmt has wrong shape. %st%s'fmt has wrong number of %% formats: %ss (%s+%sj)sinvalid fmt: %rs s+-Rs?Mismatch between array dtype ('%s') and format specifier ('%s')N(*R RRR?RlRRRRmRbRRRRNRvRwRLRtasarrayRRRR]RRRjRt iscomplexobjRRDRRBtstrR R"tcountRRRYtrealtimagR (RRR,RR-R.R/RR{R2town_fhRtncolt iscomplex_XRt n_fmt_charsterrortrowtrow2tnumbertsR((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR+s| !    !          c C`st}t|ds<tjjj|dd|}t}nz2t|tjsctj|}n|j }t|t rt|tj rt |}n0t|tj rt|t rt |}nt|dstj|}n|j|}|rTt|dt rTtj||jd}tj|d|}||_ntj|d|}|SWd|r|jnXdS(s! Construct an array from a text file, using regular expression parsing. The returned array is always a structured array, and is constructed from all matches of the regular expression in the file. Groups in the regular expression are converted to fields of the structured array. Parameters ---------- file : str or file File name or file object to read. regexp : str or regexp Regular expression used to parse the file. Groups in the regular expression correspond to fields in the dtype. dtype : dtype or list of dtypes Dtype for the structured array. encoding : str, optional Encoding used to decode the inputfile. Does not apply to input streams. .. versionadded:: 1.14.0 Returns ------- output : ndarray The output array, containing the part of the content of `file` that was matched by `regexp`. `output` is always a structured array. Raises ------ TypeError When `dtype` is not a valid dtype for a structured array. See Also -------- fromstring, loadtxt Notes ----- Dtypes for structured arrays can be specified in several forms, but all forms specify at least the data type and field name. For details see `doc.structured_arrays`. Examples -------- >>> f = open('test.dat', 'w') >>> f.write("1312 foo\n1534 bar\n444 qux") >>> f.close() >>> regexp = r"(\d+)\s+(...)" # match [digits, whitespace, anything] >>> output = np.fromregex('test.dat', regexp, ... [('num', np.int64), ('key', 'S3')]) >>> output array([(1312L, 'foo'), (1534L, 'bar'), (444L, 'qux')], dtype=[('num', '>> output['num'] array([1312, 1534, 444], dtype=int64) RJRR{tmatchiRN(RlRLRRRRmRNR RRJRRRRRR tfindallRRRRb( RPtregexpRR{R?tcontenttseqtnewdtypetoutput((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR6s.<  !! t_sf%icb`sm|dk r?|r!tdn|dkr?tdq?n|r^ddlm}m}n|pgi}t|tstdt|n|dkrd}t }nt }t }yjt|t rt |}nt|t rttjjj|dd |}t }n t|}Wn'tk rLtd t|nXtd |d |d |d |}td| d| d|d| }xt|D]t|qWd}yxxq|s,tt||} | t kr|dk r|| krdj| j|d} qn|| }qWWn4tk rdd} g}tjd|ddnX| t kr|dj}!|dk r|!|kr|d=qqn| dk r%y,g| jdD]}"|"j^q} Wq%tk r!yt| } Wq"tk r| g} q"Xq%Xnt | p1|}#| t krw|g|D]}"t!|"j^qM} d} nRt"| r|g| jdD]}"|"j^q} n| r|| } n|dk rt#|d|d| d| d| d|d| }n| dk r#t| } n| r+x_t$| D]Q\}$t"|$rd| j%|$| |>j/}?xCt$t6j7| g|D]&\}@||@}At |A}B|Bdkr qW n| r y!g| D]}"|A|"^q }AWq t8k r |?|d|BfqW q Xn*|B|#kr |?|d|BfqW n|;t,|A|rg |=t,gt.|A|D]\}C}D|Cj|Dk^q< nt |:|krW PqW qW W|r |j9n|dkr xt$|D]\}Eg|:D]}Ft:|F^q }Gy|Ej;|GWq t<k r d"}Ht=t:|:}Gxwt$|GD]e\}4}*y|Ej>|*Wq+ t?tfk r |Hd#7}H|H|4d||*f;}Ht?|Hq+ Xq+ Wq Xq Wnt |>}I|Idkrt |:|I|}Jd$|#}K|dkr/t g|>D] }"|"d|J|kr |"^q }L|>|I|L }>||L8}ng|>D]\}M|K|Mf^q6}Ht |Hr|Hj@dd%d&j|H}H|rt|Hqtj|HtAddqn|dkr|:| }:|r|<| }<qn|rGtt.gt$|D]=\}5gt=t:|:D]}N|5jB|N^q^q}:n\tt.gt$|D]=\}5gt=t:|:D]}N|5jC|N^q|^qZ}:|:}O|dkr g|D]}5|5j^q}Pgt$|PD]!\}C|CtjDkr^q|rrtjd'tjEddfd(}Qy#g|OD]}R|Q|R^qC}OWntFk roqXxD]tjG|P`_. Examples --------- >>> from io import StringIO >>> import numpy as np Comma delimited file with mixed dtype >>> s = StringIO(u"1,1.3,abcde") >>> data = np.genfromtxt(s, dtype=[('myint','i8'),('myfloat','f8'), ... ('mystring','S5')], delimiter=",") >>> data array((1, 1.3, 'abcde'), dtype=[('myint', '>> s.seek(0) # needed for StringIO example only >>> data = np.genfromtxt(s, dtype=None, ... names = ['myint','myfloat','mystring'], delimiter=",") >>> data array((1, 1.3, 'abcde'), dtype=[('myint', '>> s.seek(0) >>> data = np.genfromtxt(s, dtype="i8,f8,S5", ... names=['myint','myfloat','mystring'], delimiter=",") >>> data array((1, 1.3, 'abcde'), dtype=[('myint', '>> s = StringIO(u"11.3abcde") >>> data = np.genfromtxt(s, dtype=None, names=['intvar','fltvar','strvar'], ... delimiter=[1,3,5]) >>> data array((1, 1.3, 'abcde'), dtype=[('intvar', 't|}x%D]}||jd||SscS`s%h|]\}}|jr|qS((t_checked(Rtctc_type((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pys Ys  RtOcs`s|]}|jVqdS(N(tchar(RRO((s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pys uss4Nested fields involving objects are not supported...c3`s|]}t|VqdS(N(Rj(RRD(R(s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pys s((TR]Rtnumpy.maRPRQR RR RRNRlRRRRhRRRRmR R RRRR RRR%R&RRBRDRjR;RRRRtdescrRRRtdecodeRsRRRZRYRRRRRtupdateRRt IndexErrorRbRt iterupgradeRR"tupgradeRtinsertRt _loose_callt _strict_callRtVisibleDeprecationWarningtUnicodeEncodeErrorRt issubdtypet charactertmaxRRRtNotImplementedErrortviewRYt_maskRR(bRRRRt skip_headert skip_footerRRYtfilling_valuesRRRSRTRVRRRURXRtusemasktlooset invalid_raiseRR{RPRQR!R"town_fhdtfhdRtvalidate_namest first_valuesRtfvalROtnbcolstcurrentRgtuser_missing_valuesRCRtmisstvaluetentryt user_valuetuser_filling_valuestntfillt dtype_flattzipitRt uc_updateRRR]t user_convRRtrowstappend_to_rowstmaskstappend_to_maskstinvalidtappend_to_invalidRRtnbvaluesRtmt convertert_mtcurrent_columnterrmsgt nbinvalidtnbrowsttemplatetnbinvalid_skippedtnbt_rtdatat column_typesR`trtsized_column_typestcol_typetn_charsRt uniform_typetddtypetmdtypeRNt outputmasktttrowmaskst ishomogeneoustttypetnametmval((RR_s_/home/ec2-user/environment/lambda-staging/venv/lib64/python2.7/dist-packages/numpy/lib/npyio.pyR-s      $      "     ,   +  1      &# (    "                   ::4                  (   !    2  %       # &   VS  #    ,2"   .1 / % %   %  cK`st|ds        L@ 1    J P AC    ~      b