package scipy

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
val get_py : string -> Py.Object.t

Get an attribute of this module as a Py.Object.t. This is useful to pass a Python function to another function.

module MMFile : sig ... end
module Coo_matrix : sig ... end
module Ndarray : sig ... end
val asarray : ?dtype:Np.Dtype.t -> ?order:[ `C | `F ] -> a:[> `Ndarray ] Np.Obj.t -> unit -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

Convert the input to an array.

Parameters ---------- a : array_like Input data, in any form that can be converted to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays. dtype : data-type, optional By default, the data-type is inferred from the input data. order : 'C', 'F', optional Whether to use row-major (C-style) or column-major (Fortran-style) memory representation. Defaults to 'C'.

Returns ------- out : ndarray Array interpretation of `a`. No copy is performed if the input is already an ndarray with matching dtype and order. If `a` is a subclass of ndarray, a base class ndarray is returned.

See Also -------- asanyarray : Similar function which passes through subclasses. ascontiguousarray : Convert input to a contiguous array. asfarray : Convert input to a floating point ndarray. asfortranarray : Convert input to an ndarray with column-major memory order. asarray_chkfinite : Similar function which checks input for NaNs and Infs. fromiter : Create an array from an iterator. fromfunction : Construct an array by executing a function on grid positions.

Examples -------- Convert a list into an array:

>>> a = 1, 2 >>> np.asarray(a) array(1, 2)

Existing arrays are not copied:

>>> a = np.array(1, 2) >>> np.asarray(a) is a True

If `dtype` is set, array is copied only if dtype does not match:

>>> a = np.array(1, 2, dtype=np.float32) >>> np.asarray(a, dtype=np.float32) is a True >>> np.asarray(a, dtype=np.float64) is a False

Contrary to `asanyarray`, ndarray subclasses are not passed through:

>>> issubclass(np.recarray, np.ndarray) True >>> a = np.array((1.0, 2), (3.0, 4), dtype='f4,i4').view(np.recarray) >>> np.asarray(a) is a False >>> np.asanyarray(a) is a True

val asbytes : Py.Object.t -> Py.Object.t

None

val asstr : Py.Object.t -> Py.Object.t

None

val can_cast : ?casting:[ `No | `Equiv | `Safe | `Same_kind | `Unsafe ] -> from_: [ `Bool of bool | `F of float | `Dtype_specifier of Py.Object.t | `S of string | `Ndarray of [> `Ndarray ] Np.Obj.t | `I of int | `Dtype of Np.Dtype.t ] -> to_:[ `Dtype_specifier of Py.Object.t | `Dtype of Np.Dtype.t ] -> unit -> bool

can_cast(from_, to, casting='safe')

Returns True if cast between data types can occur according to the casting rule. If from is a scalar or array scalar, also returns True if the scalar value can be cast without overflow or truncation to an integer.

Parameters ---------- from_ : dtype, dtype specifier, scalar, or array Data type, scalar, or array to cast from. to : dtype or dtype specifier Data type to cast to. casting : 'no', 'equiv', 'safe', 'same_kind', 'unsafe', optional Controls what kind of data casting may occur.

* '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.

Returns ------- out : bool True if cast can occur according to the casting rule.

Notes ----- .. versionchanged:: 1.17.0 Casting between a simple data type and a structured one is possible only for 'unsafe' casting. Casting to multiple fields is allowed, but casting from multiple fields is not.

.. versionchanged:: 1.9.0 Casting from numeric to string types in 'safe' casting mode requires that the string dtype length is long enough to store the maximum integer/float value converted.

See also -------- dtype, result_type

Examples -------- Basic examples

>>> np.can_cast(np.int32, np.int64) True >>> np.can_cast(np.float64, complex) True >>> np.can_cast(complex, float) False

>>> np.can_cast('i8', 'f8') True >>> np.can_cast('i8', 'f4') False >>> np.can_cast('i4', 'S4') False

Casting scalars

>>> np.can_cast(100, 'i1') True >>> np.can_cast(150, 'i1') False >>> np.can_cast(150, 'u1') True

>>> np.can_cast(3.5e100, np.float32) False >>> np.can_cast(1000.0, np.float32) True

Array scalar checks the value, array does not

>>> np.can_cast(np.array(1000.0), np.float32) True >>> np.can_cast(np.array(1000.0), np.float32) False

Using the casting rules

>>> np.can_cast('i8', 'i8', 'no') True >>> np.can_cast('<i8', '>i8', 'no') False

>>> np.can_cast('<i8', '>i8', 'equiv') True >>> np.can_cast('<i4', '>i8', 'equiv') False

>>> np.can_cast('<i4', '>i8', 'safe') True >>> np.can_cast('<i8', '>i4', 'safe') False

>>> np.can_cast('<i8', '>i4', 'same_kind') True >>> np.can_cast('<i8', '>u4', 'same_kind') False

>>> np.can_cast('<i8', '>u4', 'unsafe') True

val concatenate : ?axis:int -> ?out:[> `Ndarray ] Np.Obj.t -> a:Py.Object.t -> unit -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

concatenate((a1, a2, ...), axis=0, out=None)

Join a sequence of arrays along an existing axis.

Parameters ---------- a1, a2, ... : sequence of array_like The arrays must have the same shape, except in the dimension corresponding to `axis` (the first, by default). axis : int, optional The axis along which the arrays will be joined. If axis is None, arrays are flattened before use. Default is 0. out : ndarray, optional If provided, the destination to place the result. The shape must be correct, matching that of what concatenate would have returned if no out argument were specified.

Returns ------- res : ndarray The concatenated array.

See Also -------- ma.concatenate : Concatenate function that preserves input masks. array_split : Split an array into multiple sub-arrays of equal or near-equal size. split : Split array into a list of multiple sub-arrays of equal size. hsplit : Split array into multiple sub-arrays horizontally (column wise). vsplit : Split array into multiple sub-arrays vertically (row wise). dsplit : Split array into multiple sub-arrays along the 3rd axis (depth). stack : Stack a sequence of arrays along a new axis. block : Assemble arrays from blocks. hstack : Stack arrays in sequence horizontally (column wise). vstack : Stack arrays in sequence vertically (row wise). dstack : Stack arrays in sequence depth wise (along third dimension). column_stack : Stack 1-D arrays as columns into a 2-D array.

Notes ----- When one or more of the arrays to be concatenated is a MaskedArray, this function will return a MaskedArray object instead of an ndarray, but the input masks are *not* preserved. In cases where a MaskedArray is expected as input, use the ma.concatenate function from the masked array module instead.

Examples -------- >>> a = np.array([1, 2], [3, 4]) >>> b = np.array([5, 6]) >>> np.concatenate((a, b), axis=0) array([1, 2], [3, 4], [5, 6]) >>> np.concatenate((a, b.T), axis=1) array([1, 2, 5], [3, 4, 6]) >>> np.concatenate((a, b), axis=None) array(1, 2, 3, 4, 5, 6)

This function will not preserve masking of MaskedArray inputs.

>>> a = np.ma.arange(3) >>> a1 = np.ma.masked >>> b = np.arange(2, 5) >>> a masked_array(data=0, --, 2, mask=False, True, False, fill_value=999999) >>> b array(2, 3, 4) >>> np.concatenate(a, b) masked_array(data=0, 1, 2, 2, 3, 4, mask=False, fill_value=999999) >>> np.ma.concatenate(a, b) masked_array(data=0, --, 2, 2, 3, 4, mask=False, True, False, False, False, False, fill_value=999999)

val conj : ?out: [ `Ndarray of [> `Ndarray ] Np.Obj.t | `Tuple_of_ndarray_and_None of Py.Object.t ] -> ?where:[> `Ndarray ] Np.Obj.t -> x:[> `Ndarray ] Np.Obj.t -> unit -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

conjugate(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True, signature, extobj)

Return the complex conjugate, element-wise.

The complex conjugate of a complex number is obtained by changing the sign of its imaginary part.

Parameters ---------- x : array_like Input value. out : ndarray, None, or tuple of ndarray and None, optional A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs. where : array_like, optional This condition is broadcast over the input. At locations where the condition is True, the `out` array will be set to the ufunc result. Elsewhere, the `out` array will retain its original value. Note that if an uninitialized `out` array is created via the default ``out=None``, locations within it where the condition is False will remain uninitialized. **kwargs For other keyword-only arguments, see the :ref:`ufunc docs <ufuncs.kwargs>`.

Returns ------- y : ndarray The complex conjugate of `x`, with same dtype as `y`. This is a scalar if `x` is a scalar.

Notes ----- `conj` is an alias for `conjugate`:

>>> np.conj is np.conjugate True

Examples -------- >>> np.conjugate(1+2j) (1-2j)

>>> x = np.eye(2) + 1j * np.eye(2) >>> np.conjugate(x) array([ 1.-1.j, 0.-0.j], [ 0.-0.j, 1.-1.j])

val imag : [> `Ndarray ] Np.Obj.t -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

Return the imaginary part of the complex argument.

Parameters ---------- val : array_like Input array.

Returns ------- out : ndarray or scalar The imaginary component of the complex argument. If `val` is real, the type of `val` is used for the output. If `val` has complex elements, the returned type is float.

See Also -------- real, angle, real_if_close

Examples -------- >>> a = np.array(1+2j, 3+4j, 5+6j) >>> a.imag array(2., 4., 6.) >>> a.imag = np.array(8, 10, 12) >>> a array(1. +8.j, 3.+10.j, 5.+12.j) >>> np.imag(1 + 1j) 1.0

val isspmatrix : Py.Object.t -> Py.Object.t

Is x of a sparse matrix type?

Parameters ---------- x object to check for being a sparse matrix

Returns ------- bool True if x is a sparse matrix, False otherwise

Notes ----- issparse and isspmatrix are aliases for the same function.

Examples -------- >>> from scipy.sparse import csr_matrix, isspmatrix >>> isspmatrix(csr_matrix([5])) True

>>> from scipy.sparse import isspmatrix >>> isspmatrix(5) False

val mminfo : [ `File_like of Py.Object.t | `S of string ] -> int * int * int * string * string * string

Return size and storage parameters from Matrix Market file-like 'source'.

Parameters ---------- source : str or file-like Matrix Market filename (extension .mtx) or open file-like object

Returns ------- rows : int Number of matrix rows. cols : int Number of matrix columns. entries : int Number of non-zero entries of a sparse matrix or rows*cols for a dense matrix. format : str Either 'coordinate' or 'array'. field : str Either 'real', 'complex', 'pattern', or 'integer'. symmetry : str Either 'general', 'symmetric', 'skew-symmetric', or 'hermitian'.

val mmread : [ `File_like of Py.Object.t | `S of string ] -> Py.Object.t

Reads the contents of a Matrix Market file-like 'source' into a matrix.

Parameters ---------- source : str or file-like Matrix Market filename (extensions .mtx, .mtz.gz) or open file-like object.

Returns ------- a : ndarray or coo_matrix Dense or sparse matrix depending on the matrix format in the Matrix Market file.

val mmwrite : ?comment:string -> ?field:string -> ?precision:int -> ?symmetry:string -> target:[ `File_like of Py.Object.t | `S of string ] -> a:[> `Ndarray ] Np.Obj.t -> unit -> Py.Object.t

Writes the sparse or dense array `a` to Matrix Market file-like `target`.

Parameters ---------- target : str or file-like Matrix Market filename (extension .mtx) or open file-like object. a : array like Sparse or dense 2-D array. comment : str, optional Comments to be prepended to the Matrix Market file. field : None or str, optional Either 'real', 'complex', 'pattern', or 'integer'. precision : None or int, optional Number of digits to display for real or complex values. symmetry : None or str, optional Either 'general', 'symmetric', 'skew-symmetric', or 'hermitian'. If symmetry is None the symmetry type of 'a' is determined by its values.

val ones : ?dtype:Np.Dtype.t -> ?order:[ `C | `F ] -> shape:[ `I of int | `Is of int list ] -> unit -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

Return a new array of given shape and type, filled with ones.

Parameters ---------- shape : int or sequence of ints Shape of the new array, e.g., ``(2, 3)`` or ``2``. dtype : data-type, optional The desired data-type for the array, e.g., `numpy.int8`. Default is `numpy.float64`. order : 'C', 'F', optional, default: C Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.

Returns ------- out : ndarray Array of ones with the given shape, dtype, and order.

See Also -------- ones_like : Return an array of ones with shape and type of input. empty : Return a new uninitialized array. zeros : Return a new array setting values to zero. full : Return a new array of given shape filled with value.

Examples -------- >>> np.ones(5) array(1., 1., 1., 1., 1.)

>>> np.ones((5,), dtype=int) array(1, 1, 1, 1, 1)

>>> np.ones((2, 1)) array([1.], [1.])

>>> s = (2,2) >>> np.ones(s) array([1., 1.], [1., 1.])

val real : [> `Ndarray ] Np.Obj.t -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

Return the real part of the complex argument.

Parameters ---------- val : array_like Input array.

Returns ------- out : ndarray or scalar The real component of the complex argument. If `val` is real, the type of `val` is used for the output. If `val` has complex elements, the returned type is float.

See Also -------- real_if_close, imag, angle

Examples -------- >>> a = np.array(1+2j, 3+4j, 5+6j) >>> a.real array(1., 3., 5.) >>> a.real = 9 >>> a array(9.+2.j, 9.+4.j, 9.+6.j) >>> a.real = np.array(9, 8, 7) >>> a array(9.+2.j, 8.+4.j, 7.+6.j) >>> np.real(1 + 1j) 1.0

val zeros : ?dtype:Np.Dtype.t -> ?order:[ `C | `F ] -> shape:int list -> unit -> [ `ArrayLike | `Ndarray | `Object ] Np.Obj.t

zeros(shape, dtype=float, order='C')

Return a new array of given shape and type, filled with zeros.

Parameters ---------- shape : int or tuple of ints Shape of the new array, e.g., ``(2, 3)`` or ``2``. dtype : data-type, optional The desired data-type for the array, e.g., `numpy.int8`. Default is `numpy.float64`. order : 'C', 'F', optional, default: 'C' Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.

Returns ------- out : ndarray Array of zeros with the given shape, dtype, and order.

See Also -------- zeros_like : Return an array of zeros with shape and type of input. empty : Return a new uninitialized array. ones : Return a new array setting values to one. full : Return a new array of given shape filled with value.

Examples -------- >>> np.zeros(5) array( 0., 0., 0., 0., 0.)

>>> np.zeros((5,), dtype=int) array(0, 0, 0, 0, 0)

>>> np.zeros((2, 1)) array([ 0.], [ 0.])

>>> s = (2,2) >>> np.zeros(s) array([ 0., 0.], [ 0., 0.])

>>> np.zeros((2,), dtype=('x', 'i4'), ('y', 'i4')) # custom dtype array((0, 0), (0, 0), dtype=('x', '<i4'), ('y', '<i4'))