index int64 0 731k | package stringlengths 2 98 ⌀ | name stringlengths 1 76 | docstring stringlengths 0 281k ⌀ | code stringlengths 4 1.07M ⌀ | signature stringlengths 2 42.8k ⌀ |
|---|---|---|---|---|---|
724,694 | scipy.sparse._matrix | getcol | Returns a copy of column j of the matrix, as an (m x 1) sparse
matrix (column vector).
| def getcol(self, j):
"""Returns a copy of column j of the matrix, as an (m x 1) sparse
matrix (column vector).
"""
return self._getcol(j)
| (self, j) |
724,695 | scipy.sparse._matrix | getformat | Matrix storage format | def getformat(self):
"""Matrix storage format"""
return self.format
| (self) |
724,696 | scipy.sparse._matrix | getmaxprint | Maximum number of elements to display when printed. | def getmaxprint(self):
"""Maximum number of elements to display when printed."""
return self._getmaxprint()
| (self) |
724,697 | scipy.sparse._matrix | getnnz | Number of stored values, including explicit zeros.
Parameters
----------
axis : None, 0, or 1
Select between the number of values across the whole array, in
each column, or in each row.
| def getnnz(self, axis=None):
"""Number of stored values, including explicit zeros.
Parameters
----------
axis : None, 0, or 1
Select between the number of values across the whole array, in
each column, or in each row.
"""
return self._getnnz(axis=axis)
| (self, axis=None) |
724,698 | scipy.sparse._matrix | getrow | Returns a copy of row i of the matrix, as a (1 x n) sparse
matrix (row vector).
| def getrow(self, i):
"""Returns a copy of row i of the matrix, as a (1 x n) sparse
matrix (row vector).
"""
return self._getrow(i)
| (self, i) |
724,699 | scipy.sparse._data | log1p | Element-wise log1p.
See `numpy.log1p` for more information. | def _create_method(op):
def method(self):
result = op(self._deduped_data())
return self._with_data(result, copy=True)
method.__doc__ = (f"Element-wise {name}.\n\n"
f"See `numpy.{name}` for more information.")
method.__name__ = name
return method
| (self) |
724,700 | scipy.sparse._data | max |
Return the maximum of the array/matrix or maximum along an axis.
This takes all elements into account, not just the non-zero ones.
Parameters
----------
axis : {-2, -1, 0, 1, None} optional
Axis along which the sum is computed. The default is to
compute ... | def max(self, axis=None, out=None):
"""
Return the maximum of the array/matrix or maximum along an axis.
This takes all elements into account, not just the non-zero ones.
Parameters
----------
axis : {-2, -1, 0, 1, None} optional
Axis along which the sum is computed. The default is to
... | (self, axis=None, out=None) |
724,701 | scipy.sparse._compressed | maximum | Element-wise maximum between this and another array/matrix. | def maximum(self, other):
return self._maximum_minimum(other, np.maximum,
'_maximum_', lambda x: np.asarray(x) > 0)
| (self, other) |
724,702 | scipy.sparse._base | mean |
Compute the arithmetic mean along the specified axis.
Returns the average of the array/matrix elements. The average is taken
over all elements in the array/matrix by default, otherwise over the
specified axis. `float64` intermediate and return values are used
for integer inputs... | def mean(self, axis=None, dtype=None, out=None):
"""
Compute the arithmetic mean along the specified axis.
Returns the average of the array/matrix elements. The average is taken
over all elements in the array/matrix by default, otherwise over the
specified axis. `float64` intermediate and return val... | (self, axis=None, dtype=None, out=None) |
724,703 | scipy.sparse._data | min |
Return the minimum of the array/matrix or maximum along an axis.
This takes all elements into account, not just the non-zero ones.
Parameters
----------
axis : {-2, -1, 0, 1, None} optional
Axis along which the sum is computed. The default is to
compute ... | def min(self, axis=None, out=None):
"""
Return the minimum of the array/matrix or maximum along an axis.
This takes all elements into account, not just the non-zero ones.
Parameters
----------
axis : {-2, -1, 0, 1, None} optional
Axis along which the sum is computed. The default is to
... | (self, axis=None, out=None) |
724,704 | scipy.sparse._compressed | minimum | Element-wise minimum between this and another array/matrix. | def minimum(self, other):
return self._maximum_minimum(other, np.minimum,
'_minimum_', lambda x: np.asarray(x) < 0)
| (self, other) |
724,705 | scipy.sparse._compressed | multiply | Point-wise multiplication by another array/matrix, vector, or
scalar.
| def multiply(self, other):
"""Point-wise multiplication by another array/matrix, vector, or
scalar.
"""
# Scalar multiplication.
if isscalarlike(other):
return self._mul_scalar(other)
# Sparse matrix or vector.
if issparse(other):
if self.shape == other.shape:
oth... | (self, other) |
724,706 | scipy.sparse._data | nanmax |
Return the maximum of the array/matrix or maximum along an axis, ignoring any
NaNs. This takes all elements into account, not just the non-zero
ones.
.. versionadded:: 1.11.0
Parameters
----------
axis : {-2, -1, 0, 1, None} optional
Axis along whic... | def nanmax(self, axis=None, out=None):
"""
Return the maximum of the array/matrix or maximum along an axis, ignoring any
NaNs. This takes all elements into account, not just the non-zero
ones.
.. versionadded:: 1.11.0
Parameters
----------
axis : {-2, -1, 0, 1, None} optional
Axi... | (self, axis=None, out=None) |
724,707 | scipy.sparse._data | nanmin |
Return the minimum of the array/matrix or minimum along an axis, ignoring any
NaNs. This takes all elements into account, not just the non-zero
ones.
.. versionadded:: 1.11.0
Parameters
----------
axis : {-2, -1, 0, 1, None} optional
Axis along whic... | def nanmin(self, axis=None, out=None):
"""
Return the minimum of the array/matrix or minimum along an axis, ignoring any
NaNs. This takes all elements into account, not just the non-zero
ones.
.. versionadded:: 1.11.0
Parameters
----------
axis : {-2, -1, 0, 1, None} optional
Axi... | (self, axis=None, out=None) |
724,708 | scipy.sparse._csc | nonzero | Nonzero indices of the array/matrix.
Returns a tuple of arrays (row,col) containing the indices
of the non-zero elements of the array.
Examples
--------
>>> from scipy.sparse import csr_array
>>> A = csr_array([[1,2,0],[0,0,3],[4,0,5]])
>>> A.nonzero()
(... | def nonzero(self):
# CSC can't use _cs_matrix's .nonzero method because it
# returns the indices sorted for self transposed.
# Get row and col indices, from _cs_matrix.tocoo
major_dim, minor_dim = self._swap(self.shape)
minor_indices = self.indices
major_indices = np.empty(len(minor_indices), dt... | (self) |
724,709 | scipy.sparse._data | power |
This function performs element-wise power.
Parameters
----------
n : scalar
n is a non-zero scalar (nonzero avoids dense ones creation)
If zero power is desired, special case it to use `np.ones`
dtype : If dtype is not specified, the current dtype will ... | def power(self, n, dtype=None):
"""
This function performs element-wise power.
Parameters
----------
n : scalar
n is a non-zero scalar (nonzero avoids dense ones creation)
If zero power is desired, special case it to use `np.ones`
dtype : If dtype is not specified, the current dt... | (self, n, dtype=None) |
724,710 | scipy.sparse._compressed | prune | Remove empty space after all non-zero elements.
| def prune(self):
"""Remove empty space after all non-zero elements.
"""
major_dim = self._swap(self.shape)[0]
if len(self.indptr) != major_dim + 1:
raise ValueError('index pointer has invalid length')
if len(self.indices) < self.nnz:
raise ValueError('indices array has fewer than nnz... | (self) |
724,711 | scipy.sparse._data | rad2deg | Element-wise rad2deg.
See `numpy.rad2deg` for more information. | def _create_method(op):
def method(self):
result = op(self._deduped_data())
return self._with_data(result, copy=True)
method.__doc__ = (f"Element-wise {name}.\n\n"
f"See `numpy.{name}` for more information.")
method.__name__ = name
return method
| (self) |
724,712 | scipy.sparse._base | reshape | reshape(self, shape, order='C', copy=False)
Gives a new shape to a sparse array/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
... | def reshape(self, *args, **kwargs):
"""reshape(self, shape, order='C', copy=False)
Gives a new shape to a sparse array/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'}, op... | (self, *args, **kwargs) |
724,713 | scipy.sparse._compressed | resize | Resize the array/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 ... | def resize(self, *shape):
shape = check_shape(shape)
if hasattr(self, 'blocksize'):
bm, bn = self.blocksize
new_M, rm = divmod(shape[0], bm)
new_N, rn = divmod(shape[1], bn)
if rm or rn:
raise ValueError("shape must be divisible into {} blocks. "
... | (self, *shape) |
724,714 | scipy.sparse._data | rint | Element-wise rint.
See `numpy.rint` for more information. | def _create_method(op):
def method(self):
result = op(self._deduped_data())
return self._with_data(result, copy=True)
method.__doc__ = (f"Element-wise {name}.\n\n"
f"See `numpy.{name}` for more information.")
method.__name__ = name
return method
| (self) |
724,715 | scipy.sparse._matrix | set_shape | Set the shape of the matrix in-place | def set_shape(self, shape):
"""Set the shape of the matrix in-place"""
# Make sure copy is False since this is in place
# Make sure format is unchanged because we are doing a __dict__ swap
new_self = self.reshape(shape, copy=False).asformat(self.format)
self.__dict__ = new_self.__dict__
| (self, shape) |
724,716 | scipy.sparse._base | setdiag |
Set diagonal or off-diagonal elements of the array/matrix.
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... | def setdiag(self, values, k=0):
"""
Set diagonal or off-diagonal elements of the array/matrix.
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... | (self, values, k=0) |
724,717 | scipy.sparse._data | sign | Element-wise sign.
See `numpy.sign` for more information. | def _create_method(op):
def method(self):
result = op(self._deduped_data())
return self._with_data(result, copy=True)
method.__doc__ = (f"Element-wise {name}.\n\n"
f"See `numpy.{name}` for more information.")
method.__name__ = name
return method
| (self) |
724,718 | scipy.sparse._data | sin | Element-wise sin.
See `numpy.sin` for more information. | def _create_method(op):
def method(self):
result = op(self._deduped_data())
return self._with_data(result, copy=True)
method.__doc__ = (f"Element-wise {name}.\n\n"
f"See `numpy.{name}` for more information.")
method.__name__ = name
return method
| (self) |
724,719 | scipy.sparse._data | sinh | Element-wise sinh.
See `numpy.sinh` for more information. | def _create_method(op):
def method(self):
result = op(self._deduped_data())
return self._with_data(result, copy=True)
method.__doc__ = (f"Element-wise {name}.\n\n"
f"See `numpy.{name}` for more information.")
method.__name__ = name
return method
| (self) |
724,720 | scipy.sparse._compressed | sort_indices | Sort the indices of this array/matrix *in place*
| def sort_indices(self):
"""Sort the indices of this array/matrix *in place*
"""
if not self.has_sorted_indices:
_sparsetools.csr_sort_indices(len(self.indptr) - 1, self.indptr,
self.indices, self.data)
self.has_sorted_indices = True
| (self) |
724,721 | scipy.sparse._compressed | sorted_indices | Return a copy of this array/matrix with sorted indices
| def sorted_indices(self):
"""Return a copy of this array/matrix with sorted indices
"""
A = self.copy()
A.sort_indices()
return A
# an alternative that has linear complexity is the following
# although the previous option is typically faster
# return self.toother().toother()
| (self) |
724,722 | scipy.sparse._data | sqrt | Element-wise sqrt.
See `numpy.sqrt` for more information. | def _create_method(op):
def method(self):
result = op(self._deduped_data())
return self._with_data(result, copy=True)
method.__doc__ = (f"Element-wise {name}.\n\n"
f"See `numpy.{name}` for more information.")
method.__name__ = name
return method
| (self) |
724,723 | scipy.sparse._compressed | sum |
Sum the array/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 array/matrix elements, returning a scalar
(i.e., `axis` = `... | def sum(self, axis=None, dtype=None, out=None):
"""Sum the array/matrix over the given axis. If the axis is None, sum
over both rows and columns, returning a scalar.
"""
# The _spbase base class already does axis=0 and axis=1 efficiently
# so we only do the case axis=None here
if (not hasattr(s... | (self, axis=None, dtype=None, out=None) |
724,724 | scipy.sparse._compressed | sum_duplicates | Eliminate duplicate entries by adding them together
This is an *in place* operation.
| def sum_duplicates(self):
"""Eliminate duplicate entries by adding them together
This is an *in place* operation.
"""
if self.has_canonical_format:
return
self.sort_indices()
M, N = self._swap(self.shape)
_sparsetools.csr_sum_duplicates(M, N, self.indptr, self.indices,
... | (self) |
724,725 | scipy.sparse._data | tan | Element-wise tan.
See `numpy.tan` for more information. | def _create_method(op):
def method(self):
result = op(self._deduped_data())
return self._with_data(result, copy=True)
method.__doc__ = (f"Element-wise {name}.\n\n"
f"See `numpy.{name}` for more information.")
method.__name__ = name
return method
| (self) |
724,726 | scipy.sparse._data | tanh | Element-wise tanh.
See `numpy.tanh` for more information. | def _create_method(op):
def method(self):
result = op(self._deduped_data())
return self._with_data(result, copy=True)
method.__doc__ = (f"Element-wise {name}.\n\n"
f"See `numpy.{name}` for more information.")
method.__name__ = name
return method
| (self) |
724,727 | scipy.sparse._compressed | toarray |
Return a dense ndarray representation of this sparse array/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', which prov... | def toarray(self, order=None, out=None):
if out is None and order is None:
order = self._swap('cf')[0]
out = self._process_toarray_args(order, out)
if not (out.flags.c_contiguous or out.flags.f_contiguous):
raise ValueError('Output array must be C or F contiguous')
# align ideal order wi... | (self, order=None, out=None) |
724,728 | scipy.sparse._base | tobsr | Convert this array/matrix to Block Sparse Row format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant bsr_array/matrix.
When blocksize=(R, C) is provided, it will be used for construction of
the bsr_array/matrix.
| def tobsr(self, blocksize=None, copy=False):
"""Convert this array/matrix to Block Sparse Row format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant bsr_array/matrix.
When blocksize=(R, C) is provided, it will be used for construction of
the bsr_array/mat... | (self, blocksize=None, copy=False) |
724,729 | scipy.sparse._compressed | tocoo | Convert this array/matrix to COOrdinate format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant coo_array/matrix.
| def tocoo(self, copy=True):
major_dim, minor_dim = self._swap(self.shape)
minor_indices = self.indices
major_indices = np.empty(len(minor_indices), dtype=self.indices.dtype)
_sparsetools.expandptr(major_dim, self.indptr, major_indices)
coords = self._swap((major_indices, minor_indices))
return s... | (self, copy=True) |
724,730 | scipy.sparse._csc | tocsc | Convert this array/matrix to Compressed Sparse Column format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant csc_array/matrix.
| def tocsc(self, copy=False):
if copy:
return self.copy()
else:
return self
| (self, copy=False) |
724,731 | scipy.sparse._csc | tocsr | Convert this array/matrix to Compressed Sparse Row format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant csr_array/matrix.
| def tocsr(self, copy=False):
M,N = self.shape
idx_dtype = self._get_index_dtype((self.indptr, self.indices),
maxval=max(self.nnz, N))
indptr = np.empty(M + 1, dtype=idx_dtype)
indices = np.empty(self.nnz, dtype=idx_dtype)
data = np.empty(self.nnz, dtype=upcast(self.dt... | (self, copy=False) |
724,732 | scipy.sparse._base | todense |
Return a dense representation of this sparse array/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', which provides no... | def todense(self, order=None, out=None):
"""
Return a dense representation of this sparse array/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'... | (self, order=None, out=None) |
724,733 | scipy.sparse._base | todia | Convert this array/matrix to sparse DIAgonal format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant dia_array/matrix.
| def todia(self, copy=False):
"""Convert this array/matrix to sparse DIAgonal format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant dia_array/matrix.
"""
return self.tocoo(copy=copy).todia(copy=False)
| (self, copy=False) |
724,734 | scipy.sparse._base | todok | Convert this array/matrix to Dictionary Of Keys format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant dok_array/matrix.
| def todok(self, copy=False):
"""Convert this array/matrix to Dictionary Of Keys format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant dok_array/matrix.
"""
return self.tocoo(copy=copy).todok(copy=False)
| (self, copy=False) |
724,735 | scipy.sparse._base | tolil | Convert this array/matrix to List of Lists format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant lil_array/matrix.
| def tolil(self, copy=False):
"""Convert this array/matrix to List of Lists format.
With copy=False, the data/indices may be shared between this array/matrix and
the resultant lil_array/matrix.
"""
return self.tocsr(copy=False).tolil(copy=copy)
| (self, copy=False) |
724,736 | scipy.sparse._base | trace | Returns the sum along diagonals of the sparse array/matrix.
Parameters
----------
offset : int, optional
Which diagonal to get, corresponding to elements a[i, i+offset].
Default: 0 (the main diagonal).
| def trace(self, offset=0):
"""Returns the sum along diagonals of the sparse array/matrix.
Parameters
----------
offset : int, optional
Which diagonal to get, corresponding to elements a[i, i+offset].
Default: 0 (the main diagonal).
"""
return self.diagonal(k=offset).sum()
| (self, offset=0) |
724,737 | scipy.sparse._csc | transpose |
Reverses the dimensions of the sparse array/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, opt... | def transpose(self, axes=None, copy=False):
if axes is not None and axes != (1, 0):
raise ValueError("Sparse arrays/matrices do not support "
"an 'axes' parameter because swapping "
"dimensions is the only logical permutation.")
M, N = self.shape
r... | (self, axes=None, copy=False) |
724,738 | scipy.sparse._data | trunc | Element-wise trunc.
See `numpy.trunc` for more information. | def _create_method(op):
def method(self):
result = op(self._deduped_data())
return self._with_data(result, copy=True)
method.__doc__ = (f"Element-wise {name}.\n\n"
f"See `numpy.{name}` for more information.")
method.__name__ = name
return method
| (self) |
724,739 | markov_clustering.modularity | delta_matrix |
Compute delta matrix where delta[i,j]=1 if i and j belong
to same cluster and i!=j
:param matrix: The adjacency matrix
:param clusters: The clusters returned by get_clusters
:returns: delta matrix
| def delta_matrix(matrix, clusters):
"""
Compute delta matrix where delta[i,j]=1 if i and j belong
to same cluster and i!=j
:param matrix: The adjacency matrix
:param clusters: The clusters returned by get_clusters
:returns: delta matrix
"""
if isspmatrix(matrix):
delta = dok... | (matrix, clusters) |
724,740 | scipy.sparse._dok | dok_matrix |
Dictionary Of Keys based sparse matrix.
This is an efficient structure for constructing sparse
matrices incrementally.
This can be instantiated in several ways:
dok_matrix(D)
where D is a 2-D ndarray
dok_matrix(S)
with another sparse array or matrix S (equival... | class dok_matrix(spmatrix, _dok_base):
"""
Dictionary Of Keys based sparse matrix.
This is an efficient structure for constructing sparse
matrices incrementally.
This can be instantiated in several ways:
dok_matrix(D)
where D is a 2-D ndarray
dok_matrix(S)
... | (arg1, shape=None, dtype=None, copy=False) |
724,741 | scipy.sparse._base | __abs__ | null | def __abs__(self):
return abs(self.tocsr())
| (self) |
724,742 | scipy.sparse._dok | __add__ | null | def __add__(self, other):
if isscalarlike(other):
res_dtype = upcast_scalar(self.dtype, other)
new = self._dok_container(self.shape, dtype=res_dtype)
# Add this scalar to each element.
for key in itertools.product(*[range(d) for d in self.shape]):
aij = self._dict.get(key... | (self, other) |
724,744 | scipy.sparse._dok | __contains__ | null | def __contains__(self, key):
return key in self._dict
| (self, key) |
724,745 | scipy.sparse._dok | __delitem__ | null | def __delitem__(self, key, /):
del self._dict[key]
| (self, key, /) |
724,747 | scipy.sparse._base | __eq__ | null | def __eq__(self, other):
return self.tocsr().__eq__(other)
| (self, other) |
724,748 | scipy.sparse._base | __ge__ | null | def __ge__(self, other):
return self.tocsr().__ge__(other)
| (self, other) |
724,749 | scipy.sparse._dok | __getitem__ | null | def __getitem__(self, key):
if self.ndim == 2:
return super().__getitem__(key)
if isinstance(key, tuple) and len(key) == 1:
key = key[0]
INT_TYPES = (int, np.integer)
if isinstance(key, INT_TYPES):
if key < 0:
key += self.shape[-1]
if key < 0 or key >= self.sh... | (self, key) |
724,750 | scipy.sparse._base | __gt__ | null | def __gt__(self, other):
return self.tocsr().__gt__(other)
| (self, other) |
724,753 | scipy.sparse._dok | __imul__ | null | def __imul__(self, other):
if isscalarlike(other):
self._dict.update((k, v * other) for k, v in self.items())
return self
return NotImplemented
| (self, other) |
724,754 | scipy.sparse._dok | __init__ | null | def __init__(self, arg1, shape=None, dtype=None, copy=False):
_spbase.__init__(self)
is_array = isinstance(self, sparray)
if isinstance(arg1, tuple) and isshape(arg1, allow_1d=is_array):
self._shape = check_shape(arg1, allow_1d=is_array)
self._dict = {}
self.dtype = getdtype(dtype, d... | (self, arg1, shape=None, dtype=None, copy=False) |
724,755 | scipy.sparse._dok | __ior__ | null | def __ior__(self, other):
if isinstance(other, _dok_base):
self._dict |= other._dict
else:
self._dict |= other
return self
| (self, other) |
724,757 | scipy.sparse._base | __iter__ | null | def __iter__(self):
for r in range(self.shape[0]):
yield self[r]
| (self) |
724,758 | scipy.sparse._dok | __itruediv__ | null | def __itruediv__(self, other):
if isscalarlike(other):
self._dict.update((k, v / other) for k, v in self.items())
return self
return NotImplemented
| (self, other) |
724,759 | scipy.sparse._base | __le__ | null | def __le__(self, other):
return self.tocsr().__le__(other)
| (self, other) |
724,761 | scipy.sparse._base | __lt__ | null | def __lt__(self, other):
return self.tocsr().__lt__(other)
| (self, other) |
724,764 | scipy.sparse._base | __ne__ | null | def __ne__(self, other):
return self.tocsr().__ne__(other)
| (self, other) |
724,765 | scipy.sparse._dok | __neg__ | null | def __neg__(self):
if self.dtype.kind == 'b':
raise NotImplementedError(
'Negating a sparse boolean matrix is not supported.'
)
new = self._dok_container(self.shape, dtype=self.dtype)
new._dict.update((k, -v) for k, v in self.items())
return new
| (self) |
724,767 | scipy.sparse._dok | __or__ | null | def __or__(self, other):
if isinstance(other, _dok_base):
return self._dict | other._dict
return self._dict | other
| (self, other) |
724,769 | scipy.sparse._dok | __radd__ | null | def __radd__(self, other):
return self + other # addition is comutative
| (self, other) |
724,771 | scipy.sparse._dok | __reduce__ | null | def __reduce__(self):
# this approach is necessary because __setstate__ is called after
# __setitem__ upon unpickling and since __init__ is not called there
# is no shape attribute hence it is not possible to unpickle it.
return dict.__reduce__(self)
| (self) |
724,773 | scipy.sparse._dok | __reversed__ | null | def __reversed__(self):
return self._dict.__reversed__()
| (self) |
724,776 | scipy.sparse._dok | __ror__ | null | def __ror__(self, other):
if isinstance(other, _dok_base):
return self._dict | other._dict
return self._dict | other
| (self, other) |
724,777 | scipy.sparse._base | __round__ | null | def __round__(self, ndigits=0):
return round(self.tocsr(), ndigits=ndigits)
| (self, ndigits=0) |
724,780 | scipy.sparse._dok | __setitem__ | null | def __setitem__(self, key, value):
if self.ndim == 2:
return super().__setitem__(key, value)
if isinstance(key, tuple) and len(key) == 1:
key = key[0]
INT_TYPES = (int, np.integer)
if isinstance(key, INT_TYPES):
if key < 0:
key += self.shape[-1]
if key < 0 or ... | (self, key, value) |
724,783 | scipy.sparse._dok | __truediv__ | null | def __truediv__(self, other):
if isscalarlike(other):
res_dtype = upcast_scalar(self.dtype, other)
new = self._dok_container(self.shape, dtype=res_dtype)
new._dict.update(((k, v / other) for k, v in self.items()))
return new
return self.tocsr() / other
| (self, other) |
724,784 | scipy.sparse._base | _add_dense | null | def _add_dense(self, other):
return self.tocoo()._add_dense(other)
| (self, other) |
724,785 | scipy.sparse._base | _add_sparse | null | def _add_sparse(self, other):
return self.tocsr()._add_sparse(other)
| (self, other) |
724,789 | scipy.sparse._dok | _get_arrayXarray | null | def _get_arrayXarray(self, row, col):
# inner indexing
i, j = map(np.atleast_2d, np.broadcast_arrays(row, col))
newdok = self._dok_container(i.shape, dtype=self.dtype)
for key in itertools.product(range(i.shape[0]), range(i.shape[1])):
v = self._dict.get((i[key], j[key]), 0)
if v:
... | (self, row, col) |
724,790 | scipy.sparse._dok | _get_arrayXint | null | def _get_arrayXint(self, row, col):
row = row.squeeze()
return self._get_columnXarray(row, [col])
| (self, row, col) |
724,791 | scipy.sparse._dok | _get_arrayXslice | null | def _get_arrayXslice(self, row, col):
col = list(range(*col.indices(self.shape[1])))
return self._get_columnXarray(row, col)
| (self, row, col) |
724,792 | scipy.sparse._dok | _get_columnXarray | null | def _get_columnXarray(self, row, col):
# outer indexing
newdok = self._dok_container((len(row), len(col)), dtype=self.dtype)
for i, r in enumerate(row):
for j, c in enumerate(col):
v = self._dict.get((r, c), 0)
if v:
newdok._dict[i, j] = v
return newdok
| (self, row, col) |
724,794 | scipy.sparse._dok | _get_int | null | def _get_int(self, idx):
return self._dict.get(idx, self.dtype.type(0))
| (self, idx) |
724,795 | scipy.sparse._dok | _get_intXarray | null | def _get_intXarray(self, row, col):
col = col.squeeze()
return self._get_columnXarray([row], col)
| (self, row, col) |
724,796 | scipy.sparse._dok | _get_intXint | null | def _get_intXint(self, row, col):
return self._dict.get((row, col), self.dtype.type(0))
| (self, row, col) |
724,797 | scipy.sparse._dok | _get_intXslice | null | def _get_intXslice(self, row, col):
return self._get_sliceXslice(slice(row, row + 1), col)
| (self, row, col) |
724,798 | scipy.sparse._dok | _get_sliceXarray | null | def _get_sliceXarray(self, row, col):
row = list(range(*row.indices(self.shape[0])))
return self._get_columnXarray(row, col)
| (self, row, col) |
724,799 | scipy.sparse._dok | _get_sliceXint | null | def _get_sliceXint(self, row, col):
return self._get_sliceXslice(row, slice(col, col + 1))
| (self, row, col) |
724,800 | scipy.sparse._dok | _get_sliceXslice | null | def _get_sliceXslice(self, row, col):
row_start, row_stop, row_step = row.indices(self.shape[0])
col_start, col_stop, col_step = col.indices(self.shape[1])
row_range = range(row_start, row_stop, row_step)
col_range = range(col_start, col_stop, col_step)
shape = (len(row_range), len(col_range))
#... | (self, row, col) |
724,801 | scipy.sparse._base | _getcol | Returns a copy of column j of the array, as an (m x 1) sparse
array (column vector).
| def _getcol(self, j):
"""Returns a copy of column j of the array, as an (m x 1) sparse
array (column vector).
"""
if self.ndim == 1:
raise ValueError("getcol not provided for 1d arrays. Use indexing A[j]")
# Subclasses should override this method for efficiency.
# Post-multiply by a (n x... | (self, j) |
724,803 | scipy.sparse._dok | _getnnz | Number of stored values, including explicit zeros.
Parameters
----------
axis : None, 0, or 1
Select between the number of values across the whole array, in
each column, or in each row.
See also
--------
count_nonzero : Number of non-zero entries... | def _getnnz(self, axis=None):
if axis is not None:
raise NotImplementedError(
"_getnnz over an axis is not implemented for DOK format."
)
return len(self._dict)
| (self, axis=None) |
724,804 | scipy.sparse._base | _getrow | Returns a copy of row i of the array, as a (1 x n) sparse
array (row vector).
| def _getrow(self, i):
"""Returns a copy of row i of the array, as a (1 x n) sparse
array (row vector).
"""
if self.ndim == 1:
raise ValueError("getrow not meaningful for a 1d array")
# Subclasses should override this method for efficiency.
# Pre-multiply by a (1 x m) row vector 'a' conta... | (self, i) |
724,805 | scipy.sparse._base | _imag | null | def _imag(self):
return self.tocsr()._imag()
| (self) |
724,807 | scipy.sparse._dok | _matmul_multivector | null | def _matmul_multivector(self, other):
result_dtype = upcast(self.dtype, other.dtype)
# vector @ multivector
if self.ndim == 1:
# works for other 1d or 2d
return sum(v * other[j] for j, v in self._dict.items())
# matrix @ multivector
M = self.shape[0]
new_shape = (M,) if other.ndi... | (self, other) |
724,808 | scipy.sparse._base | _matmul_sparse | null | def _matmul_sparse(self, other):
return self.tocsr()._matmul_sparse(other)
| (self, other) |
724,809 | scipy.sparse._dok | _matmul_vector | null | def _matmul_vector(self, other):
res_dtype = upcast(self.dtype, other.dtype)
# vector @ vector
if self.ndim == 1:
if issparse(other):
if other.format == "dok":
keys = self.keys() & other.keys()
else:
keys = self.keys() & other.tocoo().coords[0]... | (self, other) |
724,810 | scipy.sparse._dok | _mul_scalar | null | def _mul_scalar(self, other):
res_dtype = upcast_scalar(self.dtype, other)
# Multiply this scalar by every element.
new = self._dok_container(self.shape, dtype=res_dtype)
new._dict.update(((k, v * other) for k, v in self.items()))
return new
| (self, other) |
724,813 | scipy.sparse._base | _real | null | def _real(self):
return self.tocsr()._real()
| (self) |
724,816 | scipy.sparse._dok | _set_arrayXarray | null | def _set_arrayXarray(self, row, col, x):
row = list(map(int, row.ravel()))
col = list(map(int, col.ravel()))
x = x.ravel()
self._dict.update(zip(zip(row, col), x))
for i in np.nonzero(x == 0)[0]:
key = (row[i], col[i])
if self._dict[key] == 0:
# may have been superseded b... | (self, row, col, x) |
724,817 | scipy.sparse._index | _set_arrayXarray_sparse | null | def _set_arrayXarray_sparse(self, row, col, x):
# Fall back to densifying x
x = np.asarray(x.toarray(), dtype=self.dtype)
x, _ = _broadcast_arrays(x, row)
self._set_arrayXarray(row, col, x)
| (self, row, col, x) |
724,818 | scipy.sparse._dok | _set_int | null | def _set_int(self, idx, x):
if x:
self._dict[idx] = x
elif idx in self._dict:
del self._dict[idx]
| (self, idx, x) |
724,819 | scipy.sparse._dok | _set_intXint | null | def _set_intXint(self, row, col, x):
key = (row, col)
if x:
self._dict[key] = x
elif key in self._dict:
del self._dict[key]
| (self, row, col, x) |
724,820 | scipy.sparse._base | _setdiag | This part of the implementation gets overridden by the
different formats.
| def _setdiag(self, values, k):
"""This part of the implementation gets overridden by the
different formats.
"""
M, N = self.shape
if k < 0:
if values.ndim == 0:
# broadcast
max_index = min(M+k, N)
for i in range(max_index):
self[i - k, i] =... | (self, values, k) |
724,822 | scipy.sparse._base | _sub_sparse | null | def _sub_sparse(self, other):
return self.tocsr()._sub_sparse(other)
| (self, other) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.