L iH<ddlZddlZddgZedZddZdZy) Nsave_npzload_npzF) allow_pickleci}|jdvr(|j|j|jn~|jdk(r|j|jnR|jdk(r(|j|j |j nd|jd}t||j|jjd |j|j t|tjjr|jd |rtj |fi|y tj"|fi|y )aj Save a sparse matrix or array to a file using ``.npz`` format. Parameters ---------- file : str or file-like object Either the file name (string) or an open file (file-like object) where the data will be saved. If file is a string, the ``.npz`` extension will be appended to the file name if it is not already there. matrix: spmatrix or sparray The sparse matrix or array to save. Supported formats: ``csc``, ``csr``, ``bsr``, ``dia`` or ``coo``. compressed : bool, optional Allow compressing the file. Default: True See Also -------- scipy.sparse.load_npz: Load a sparse matrix from a file using ``.npz`` format. numpy.savez: Save several arrays into a ``.npz`` archive. numpy.savez_compressed : Save several arrays into a compressed ``.npz`` archive. Examples -------- Store sparse matrix to disk, and load it again: >>> import numpy as np >>> import scipy as sp >>> sparse_matrix = sp.sparse.csc_matrix([[0, 0, 3], [4, 0, 0]]) >>> sparse_matrix >>> sparse_matrix.toarray() array([[0, 0, 3], [4, 0, 0]], dtype=int64) >>> sp.sparse.save_npz('/tmp/sparse_matrix.npz', sparse_matrix) >>> sparse_matrix = sp.sparse.load_npz('/tmp/sparse_matrix.npz') >>> sparse_matrix >>> sparse_matrix.toarray() array([[0, 0, 3], [4, 0, 0]], dtype=int64) csccsrbsr)indicesindptrdia)offsetscoo)rowcolz4Save is not implemented for sparse matrix of format .ascii)formatshapedataT) _is_arrayN)rupdater r rrrNotImplementedErrorencoderr isinstancespsparsesparraynpsavez_compressedsavez)filematrix compressed arrays_dictmsgs ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/sparse/_matrix_io.pyrr s\K }}--6>>&--H % 6>>2 % vzzvzz:DV]]OSTU!#&&}}##G,ll [[ &"))++,T* D0K0 %%ctj|fit5}|jd}|t d|d|j }t |ts|jd}|jdr|dz}n|dz} ttj|}|d vr"||d |d |df|dcdddS|dk(r||d |df|dcdddS|dk(r#||d |d|dff|dcdddStd|d#t$r}t d |d |d}~wwxYw#1swYyxYw)a Load a sparse array/matrix from a file using ``.npz`` format. Parameters ---------- file : str or file-like object Either the file name (string) or an open file (file-like object) where the data will be loaded. Returns ------- result : csc_array, csr_array, bsr_array, dia_array or coo_array A sparse array/matrix containing the loaded data. Raises ------ OSError If the input file does not exist or cannot be read. See Also -------- scipy.sparse.save_npz: Save a sparse array/matrix to a file using ``.npz`` format. numpy.load: Load several arrays from a ``.npz`` archive. Examples -------- Store sparse array/matrix to disk, and load it again: >>> import numpy as np >>> import scipy as sp >>> sparse_array = sp.sparse.csc_array([[0, 0, 3], [4, 0, 0]]) >>> sparse_array >>> sparse_array.toarray() array([[0, 0, 3], [4, 0, 0]], dtype=int64) >>> sp.sparse.save_npz('/tmp/sparse_array.npz', sparse_array) >>> sparse_array = sp.sparse.load_npz('/tmp/sparse_array.npz') >>> sparse_array >>> sparse_array.toarray() array([[0, 0, 3], [4, 0, 0]], dtype=int64) In this example we force the result to be csr_array from csr_matrix >>> sparse_matrix = sp.sparse.csc_matrix([[0, 0, 3], [4, 0, 0]]) >>> sp.sparse.save_npz('/tmp/sparse_matrix.npz', sparse_matrix) >>> tmp = sp.sparse.load_npz('/tmp/sparse_matrix.npz') >>> sparse_array = sp.sparse.csr_array(tmp) rNz The file z+ does not contain a sparse array or matrix.rr_array_matrixzUnknown format ""rrr r r)rr rrrrz4Load is not implemented for sparse matrix of format r)rload PICKLE_KWARGSget ValueErroritemrstrdecodegetattrrrAttributeErrorr)r"loaded sparse_format sparse_typeclses r'rrPsl  ' '!S6 8,  y/9:; ;%**, --*009M ::k "'(2K')3K G")) }6C 1 1vy(96(;KL#G_./!S!S2e #vy(9:#G_.5!S!S8e #vu (FG#G_.;!S!S@&)AANq'RS S G/ }A>?Q F G'!S!SsBA0E D''E E0EE' E0EEEE)T) numpyrscipyr__all__dictr.rrr(r'r@s/ z "%( B&JWSr(