Ejemplo n.º 1
0
    def diags(self, format='dia'):
        """Return a regular sparse matrix of specified format

        Parameters
        ----------
            format : str, optional
                     Choice of matrix type (see scipy.sparse.diags)

                     - dia - Sparse matrix with DIAgonal storage
                     - csr - Compressed sparse row

        Note
        ----
        This method does not return the matrix scaled by self.scale. Make sure
        to include the scale if the returned matrix is to be used in further
        calculations

        """
        if self._diags is None:
            self._diags = sp_diags(list(self.values()),
                                   list(self.keys()),
                                   shape=self.shape,
                                   format=format)

        if self._diags.format != format:
            self._diags = sp_diags(list(self.values()),
                                   list(self.keys()),
                                   shape=self.shape,
                                   format=format)

        return self._diags
Ejemplo n.º 2
0
    def diags(self, format='dia'):
        """Return a regular sparse matrix of specified format

        Parameters
        ----------
        format : str, optional
            Choice of matrix type (see scipy.sparse.diags)

            - dia - Sparse matrix with DIAgonal storage
            - csr - Compressed sparse row

        Note
        ----
        This method returns the matrix scaled by self.scale.

        """
        #if self._diags.shape != self.shape or self._diags.format != format:
        self._diags = sp_diags(list(self.values()), list(self.keys()),
                               shape=self.shape, format=format)
        scale = self.scale
        if isinstance(scale, np.ndarray):
            scale = np.atleast_1d(scale).item()
        self._diags = self._diags*scale

        return self._diags