package scipy

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Sparse.Dia_matrixSource

Sourcetype tag = [
  1. | `Dia_matrix
]
Sourcetype t = [ `ArrayLike | `Dia_matrix | `Object ] Obj.t
Sourceval of_pyobject : Py.Object.t -> t
Sourceval to_pyobject : [> tag ] Obj.t -> Py.Object.t
Sourceval create : ?shape:Py.Object.t -> ?dtype:Py.Object.t -> ?copy:Py.Object.t -> arg1:Py.Object.t -> unit -> t

Sparse matrix with DIAgonal storage

This can be instantiated in several ways: dia_matrix(D) with a dense matrix

dia_matrix(S) with another sparse matrix S (equivalent to S.todia())

dia_matrix((M, N), dtype) to construct an empty matrix with shape (M, N), dtype is optional, defaulting to dtype='d'.

dia_matrix((data, offsets), shape=(M, N)) where the ``datak,:`` stores the diagonal entries for diagonal ``offsetsk`` (See example below)

Attributes ---------- dtype : dtype Data type of the matrix shape : 2-tuple Shape of the matrix ndim : int Number of dimensions (this is always 2) nnz Number of stored values, including explicit zeros data DIA format data array of the matrix offsets DIA format offset array of the matrix

Notes -----

Sparse matrices can be used in arithmetic operations: they support addition, subtraction, multiplication, division, and matrix power.

Examples --------

>>> import numpy as np >>> from scipy.sparse import dia_matrix >>> dia_matrix((3, 4), dtype=np.int8).toarray() array([0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], dtype=int8)

>>> data = np.array([1, 2, 3, 4]).repeat(3, axis=0) >>> offsets = np.array(0, -1, 2) >>> dia_matrix((data, offsets), shape=(4, 4)).toarray() array([1, 0, 3, 0], [1, 2, 0, 4], [0, 2, 3, 0], [0, 0, 3, 4])

>>> from scipy.sparse import dia_matrix >>> n = 10 >>> ex = np.ones(n) >>> data = np.array(ex, 2 * ex, ex) >>> offsets = np.array(-1, 0, 1) >>> dia_matrix((data, offsets), shape=(n, n)).toarray() array([2., 1., 0., ..., 0., 0., 0.], [1., 2., 1., ..., 0., 0., 0.], [0., 1., 2., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 2., 1., 0.], [0., 0., 0., ..., 1., 2., 1.], [0., 0., 0., ..., 0., 1., 2.])

Sourceval __iter__ : [> tag ] Obj.t -> Py.Object.t

None

Sourceval arcsin : [> tag ] Obj.t -> Py.Object.t

Element-wise arcsin.

See `numpy.arcsin` for more information.

Sourceval arcsinh : [> tag ] Obj.t -> Py.Object.t

Element-wise arcsinh.

See `numpy.arcsinh` for more information.

Sourceval arctan : [> tag ] Obj.t -> Py.Object.t

Element-wise arctan.

See `numpy.arctan` for more information.

Sourceval arctanh : [> tag ] Obj.t -> Py.Object.t

Element-wise arctanh.

See `numpy.arctanh` for more information.

Sourceval asformat : ?copy:bool -> format:[ `S of string | `None ] -> [> tag ] Obj.t -> Py.Object.t

Return this matrix in the passed format.

Parameters ---------- format : str, None The desired matrix format ('csr', 'csc', 'lil', 'dok', 'array', ...) or None for no conversion. copy : bool, optional If True, the result is guaranteed to not share data with self.

Returns ------- A : This matrix in the passed format.

Sourceval asfptype : [> tag ] Obj.t -> Py.Object.t

Upcast matrix to a floating point format (if necessary)

Sourceval astype : ?casting:[ `No | `Equiv | `Safe | `Same_kind | `Unsafe ] -> ?copy:bool -> dtype:[ `S of string | `Dtype of Np.Dtype.t ] -> [> tag ] Obj.t -> Py.Object.t

Cast the matrix elements to a specified type.

Parameters ---------- dtype : string or numpy dtype Typecode or data-type to which to cast the data. casting : 'no', 'equiv', 'safe', 'same_kind', 'unsafe', optional Controls what kind of data casting may occur. Defaults to 'unsafe' for backwards compatibility. 'no' means the data types should not be cast at all. 'equiv' means only byte-order changes are allowed. 'safe' means only casts which can preserve values are allowed. 'same_kind' means only safe casts or casts within a kind, like float64 to float32, are allowed. 'unsafe' means any data conversions may be done. copy : bool, optional If `copy` is `False`, the result might share some memory with this matrix. If `copy` is `True`, it is guaranteed that the result and this matrix do not share any memory.

Sourceval ceil : [> tag ] Obj.t -> Py.Object.t

Element-wise ceil.

See `numpy.ceil` for more information.

Sourceval conj : ?copy:bool -> [> tag ] Obj.t -> Py.Object.t

Element-wise complex conjugation.

If the matrix is of non-complex data type and `copy` is False, this method does nothing and the data is not copied.

Parameters ---------- copy : bool, optional If True, the result is guaranteed to not share data with self.

Returns ------- A : The element-wise complex conjugate.

Sourceval conjugate : ?copy:bool -> [> tag ] Obj.t -> Py.Object.t

Element-wise complex conjugation.

If the matrix is of non-complex data type and `copy` is False, this method does nothing and the data is not copied.

Parameters ---------- copy : bool, optional If True, the result is guaranteed to not share data with self.

Returns ------- A : The element-wise complex conjugate.

Sourceval copy : [> tag ] Obj.t -> Py.Object.t

Returns a copy of this matrix.

No data/indices will be shared between the returned value and current matrix.

Sourceval count_nonzero : [> tag ] Obj.t -> Py.Object.t

Number of non-zero entries, equivalent to

np.count_nonzero(a.toarray())

Unlike getnnz() and the nnz property, which return the number of stored entries (the length of the data attribute), this method counts the actual number of non-zero entries in data.

Sourceval deg2rad : [> tag ] Obj.t -> Py.Object.t

Element-wise deg2rad.

See `numpy.deg2rad` for more information.

Sourceval diagonal : ?k:int -> [> tag ] Obj.t -> Py.Object.t

Returns the kth diagonal of the matrix.

Parameters ---------- k : int, optional Which diagonal to get, corresponding to elements ai, i+k. Default: 0 (the main diagonal).

.. versionadded:: 1.0

See also -------- numpy.diagonal : Equivalent numpy function.

Examples -------- >>> from scipy.sparse import csr_matrix >>> A = csr_matrix([1, 2, 0], [0, 0, 3], [4, 0, 5]) >>> A.diagonal() array(1, 0, 5) >>> A.diagonal(k=1) array(2, 3)

Sourceval dot : other:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Ordinary dot product

Examples -------- >>> import numpy as np >>> from scipy.sparse import csr_matrix >>> A = csr_matrix([1, 2, 0], [0, 0, 3], [4, 0, 5]) >>> v = np.array(1, 0, -1) >>> A.dot(v) array( 1, -3, -1, dtype=int64)

Sourceval expm1 : [> tag ] Obj.t -> Py.Object.t

Element-wise expm1.

See `numpy.expm1` for more information.

Sourceval floor : [> tag ] Obj.t -> Py.Object.t

Element-wise floor.

See `numpy.floor` for more information.

Sourceval getH : [> tag ] Obj.t -> Py.Object.t

Return the Hermitian transpose of this matrix.

See Also -------- numpy.matrix.getH : NumPy's implementation of `getH` for matrices

Sourceval get_shape : [> tag ] Obj.t -> Py.Object.t

Get shape of a matrix.

Sourceval getcol : j:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Returns a copy of column j of the matrix, as an (m x 1) sparse matrix (column vector).

Sourceval getformat : [> tag ] Obj.t -> Py.Object.t

Format of a matrix representation as a string.

Sourceval getmaxprint : [> tag ] Obj.t -> Py.Object.t

Maximum number of elements to display when printed.

Sourceval getnnz : ?axis:[ `One | `Zero ] -> [> tag ] Obj.t -> Py.Object.t

Number of stored values, including explicit zeros.

Parameters ---------- axis : None, 0, or 1 Select between the number of values across the whole matrix, in each column, or in each row.

See also -------- count_nonzero : Number of non-zero entries

Sourceval getrow : i:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Returns a copy of row i of the matrix, as a (1 x n) sparse matrix (row vector).

Sourceval log1p : [> tag ] Obj.t -> Py.Object.t

Element-wise log1p.

See `numpy.log1p` for more information.

Sourceval maximum : other:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Element-wise maximum between this and another matrix.

Sourceval mean : ?axis:[ `One | `Zero | `PyObject of Py.Object.t ] -> ?dtype:Np.Dtype.t -> ?out:[> `Ndarray ] Np.Obj.t -> [> tag ] Obj.t -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

Compute the arithmetic mean along the specified axis.

Returns the average of the matrix elements. The average is taken over all elements in the matrix by default, otherwise over the specified axis. `float64` intermediate and return values are used for integer inputs.

Parameters ---------- axis :

2, -1, 0, 1, None

}

optional Axis along which the mean is computed. The default is to compute the mean of all elements in the matrix (i.e., `axis` = `None`). dtype : data-type, optional Type to use in computing the mean. For integer inputs, the default is `float64`; for floating point inputs, it is the same as the input dtype.

.. versionadded:: 0.18.0

out : np.matrix, optional Alternative output matrix in which to place the result. It must have the same shape as the expected output, but the type of the output values will be cast if necessary.

.. versionadded:: 0.18.0

Returns ------- m : np.matrix

See Also -------- numpy.matrix.mean : NumPy's implementation of 'mean' for matrices

Sourceval minimum : other:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Element-wise minimum between this and another matrix.

Sourceval multiply : other:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Point-wise multiplication by another matrix

Sourceval nonzero : [> tag ] Obj.t -> Py.Object.t

nonzero indices

Returns a tuple of arrays (row,col) containing the indices of the non-zero elements of the matrix.

Examples -------- >>> from scipy.sparse import csr_matrix >>> A = csr_matrix([1,2,0],[0,0,3],[4,0,5]) >>> A.nonzero() (array(0, 0, 1, 2, 2), array(0, 1, 2, 0, 2))

Sourceval power : ?dtype:Py.Object.t -> n:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

This function performs element-wise power.

Parameters ---------- n : n is a scalar

dtype : If dtype is not specified, the current dtype will be preserved.

Sourceval rad2deg : [> tag ] Obj.t -> Py.Object.t

Element-wise rad2deg.

See `numpy.rad2deg` for more information.

Sourceval reshape : ?kwargs:(string * Py.Object.t) list -> Py.Object.t list -> [> tag ] Obj.t -> [ `ArrayLike | `Object | `Spmatrix ] Np.Obj.t

reshape(self, shape, order='C', copy=False)

Gives a new shape to a sparse matrix without changing its data.

Parameters ---------- shape : length-2 tuple of ints The new shape should be compatible with the original shape. order : 'C', 'F', optional Read the elements using this index order. 'C' means to read and write the elements using C-like index order; e.g., read entire first row, then second row, etc. 'F' means to read and write the elements using Fortran-like index order; e.g., read entire first column, then second column, etc. copy : bool, optional Indicates whether or not attributes of self should be copied whenever possible. The degree to which attributes are copied varies depending on the type of sparse matrix being used.

Returns ------- reshaped_matrix : sparse matrix A sparse matrix with the given `shape`, not necessarily of the same format as the current object.

See Also -------- numpy.matrix.reshape : NumPy's implementation of 'reshape' for matrices

Sourceval resize : Py.Object.t list -> [> tag ] Obj.t -> Py.Object.t

Resize the matrix in-place to dimensions given by ``shape``

Any elements that lie within the new shape will remain at the same indices, while non-zero elements lying outside the new shape are removed.

Parameters ---------- shape : (int, int) number of rows and columns in the new matrix

Notes ----- The semantics are not identical to `numpy.ndarray.resize` or `numpy.resize`. Here, the same data will be maintained at each index before and after reshape, if that index is within the new bounds. In numpy, resizing maintains contiguity of the array, moving elements around in the logical matrix but not within a flattened representation.

We give no guarantees about whether the underlying data attributes (arrays, etc.) will be modified in place or replaced with new objects.

Sourceval rint : [> tag ] Obj.t -> Py.Object.t

Element-wise rint.

See `numpy.rint` for more information.

Sourceval set_shape : shape:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

See `reshape`.

Sourceval setdiag : ?k:int -> values:[> `Ndarray ] Np.Obj.t -> [> tag ] Obj.t -> Py.Object.t

Set diagonal or off-diagonal elements of the array.

Parameters ---------- values : array_like New values of the diagonal elements.

Values may have any length. If the diagonal is longer than values, then the remaining diagonal entries will not be set. If values if longer than the diagonal, then the remaining values are ignored.

If a scalar value is given, all of the diagonal is set to it.

k : int, optional Which off-diagonal to set, corresponding to elements ai,i+k. Default: 0 (the main diagonal).

Sourceval sign : [> tag ] Obj.t -> Py.Object.t

Element-wise sign.

See `numpy.sign` for more information.

Sourceval sin : [> tag ] Obj.t -> Py.Object.t

Element-wise sin.

See `numpy.sin` for more information.

Sourceval sinh : [> tag ] Obj.t -> Py.Object.t

Element-wise sinh.

See `numpy.sinh` for more information.

Sourceval sqrt : [> tag ] Obj.t -> Py.Object.t

Element-wise sqrt.

See `numpy.sqrt` for more information.

Sourceval sum : ?axis:[ `One | `Zero | `PyObject of Py.Object.t ] -> ?dtype:Np.Dtype.t -> ?out:[> `Ndarray ] Np.Obj.t -> [> tag ] Obj.t -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

Sum the matrix elements over a given axis.

Parameters ---------- axis :

2, -1, 0, 1, None

}

optional Axis along which the sum is computed. The default is to compute the sum of all the matrix elements, returning a scalar (i.e., `axis` = `None`). dtype : dtype, optional The type of the returned matrix and of the accumulator in which the elements are summed. The dtype of `a` is used by default unless `a` has an integer dtype of less precision than the default platform integer. In that case, if `a` is signed then the platform integer is used while if `a` is unsigned then an unsigned integer of the same precision as the platform integer is used.

.. versionadded:: 0.18.0

out : np.matrix, optional Alternative output matrix in which to place the result. It must have the same shape as the expected output, but the type of the output values will be cast if necessary.

.. versionadded:: 0.18.0

Returns ------- sum_along_axis : np.matrix A matrix with the same shape as `self`, with the specified axis removed.

See Also -------- numpy.matrix.sum : NumPy's implementation of 'sum' for matrices

Sourceval tan : [> tag ] Obj.t -> Py.Object.t

Element-wise tan.

See `numpy.tan` for more information.

Sourceval tanh : [> tag ] Obj.t -> Py.Object.t

Element-wise tanh.

See `numpy.tanh` for more information.

Sourceval toarray : ?order:[ `C | `F ] -> ?out:[ `Ndarray of [> `Ndarray ] Np.Obj.t | `T2_D of Py.Object.t ] -> [> tag ] Obj.t -> Py.Object.t

Return a dense ndarray representation of this matrix.

Parameters ---------- order : 'C', 'F', optional Whether to store multidimensional data in C (row-major) or Fortran (column-major) order in memory. The default is 'None', indicating the NumPy default of C-ordered. Cannot be specified in conjunction with the `out` argument.

out : ndarray, 2-D, optional If specified, uses this array as the output buffer instead of allocating a new array to return. The provided array must have the same shape and dtype as the sparse matrix on which you are calling the method. For most sparse types, `out` is required to be memory contiguous (either C or Fortran ordered).

Returns ------- arr : ndarray, 2-D An array with the same shape and containing the same data represented by the sparse matrix, with the requested memory order. If `out` was passed, the same object is returned after being modified in-place to contain the appropriate values.

Sourceval tobsr : ?blocksize:Py.Object.t -> ?copy:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Convert this matrix to Block Sparse Row format.

With copy=False, the data/indices may be shared between this matrix and the resultant bsr_matrix.

When blocksize=(R, C) is provided, it will be used for construction of the bsr_matrix.

Sourceval tocoo : ?copy:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Convert this matrix to COOrdinate format.

With copy=False, the data/indices may be shared between this matrix and the resultant coo_matrix.

Sourceval tocsc : ?copy:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Convert this matrix to Compressed Sparse Column format.

With copy=False, the data/indices may be shared between this matrix and the resultant csc_matrix.

Sourceval tocsr : ?copy:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Convert this matrix to Compressed Sparse Row format.

With copy=False, the data/indices may be shared between this matrix and the resultant csr_matrix.

Sourceval todense : ?order:[ `C | `F ] -> ?out:[ `Ndarray of [> `Ndarray ] Np.Obj.t | `T2_D of Py.Object.t ] -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Return a dense matrix representation of this matrix.

Parameters ---------- order : 'C', 'F', optional Whether to store multi-dimensional data in C (row-major) or Fortran (column-major) order in memory. The default is 'None', indicating the NumPy default of C-ordered. Cannot be specified in conjunction with the `out` argument.

out : ndarray, 2-D, optional If specified, uses this array (or `numpy.matrix`) as the output buffer instead of allocating a new array to return. The provided array must have the same shape and dtype as the sparse matrix on which you are calling the method.

Returns ------- arr : numpy.matrix, 2-D A NumPy matrix object with the same shape and containing the same data represented by the sparse matrix, with the requested memory order. If `out` was passed and was an array (rather than a `numpy.matrix`), it will be filled with the appropriate values and returned wrapped in a `numpy.matrix` object that shares the same memory.

Sourceval todia : ?copy:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Convert this matrix to sparse DIAgonal format.

With copy=False, the data/indices may be shared between this matrix and the resultant dia_matrix.

Sourceval todok : ?copy:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Convert this matrix to Dictionary Of Keys format.

With copy=False, the data/indices may be shared between this matrix and the resultant dok_matrix.

Sourceval tolil : ?copy:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Convert this matrix to List of Lists format.

With copy=False, the data/indices may be shared between this matrix and the resultant lil_matrix.

Sourceval transpose : ?axes:Py.Object.t -> ?copy:bool -> [> tag ] Obj.t -> Py.Object.t

Reverses the dimensions of the sparse matrix.

Parameters ---------- axes : None, optional This argument is in the signature *solely* for NumPy compatibility reasons. Do not pass in anything except for the default value. copy : bool, optional Indicates whether or not attributes of `self` should be copied whenever possible. The degree to which attributes are copied varies depending on the type of sparse matrix being used.

Returns ------- p : `self` with the dimensions reversed.

See Also -------- numpy.matrix.transpose : NumPy's implementation of 'transpose' for matrices

Sourceval trunc : [> tag ] Obj.t -> Py.Object.t

Element-wise trunc.

See `numpy.trunc` for more information.

Sourceval dtype : t -> Np.Dtype.t

Attribute dtype: get value or raise Not_found if None.

Sourceval dtype_opt : t -> Np.Dtype.t option

Attribute dtype: get value as an option.

Sourceval shape : t -> Py.Object.t

Attribute shape: get value or raise Not_found if None.

Sourceval shape_opt : t -> Py.Object.t option

Attribute shape: get value as an option.

Sourceval ndim : t -> int

Attribute ndim: get value or raise Not_found if None.

Sourceval ndim_opt : t -> int option

Attribute ndim: get value as an option.

Sourceval nnz : t -> Py.Object.t

Attribute nnz: get value or raise Not_found if None.

Sourceval nnz_opt : t -> Py.Object.t option

Attribute nnz: get value as an option.

Sourceval data : t -> Py.Object.t

Attribute data: get value or raise Not_found if None.

Sourceval data_opt : t -> Py.Object.t option

Attribute data: get value as an option.

Sourceval offsets : t -> Py.Object.t

Attribute offsets: get value or raise Not_found if None.

Sourceval offsets_opt : t -> Py.Object.t option

Attribute offsets: get value as an option.

Sourceval to_string : t -> string

Print the object to a human-readable representation.

Sourceval show : t -> string

Print the object to a human-readable representation.

Sourceval pp : Format.formatter -> t -> unit

Pretty-print the object to a formatter.

OCaml

Innovation. Community. Security.