INNER CODE UNIT · Python

entries

webartifex/intro-to-python · 11_classes/sample_package/matrix.py:174

    def entries(self, *, reverse=False, row_major=True):
        """Loop over a Matrix's entries.

        Args:
            reverse (bool): flag to loop backwards; defaults to False
            row_major (bool): flag to loop in row-major order; defaults to True

        Returns:
            entries (generator): produces a Matrix's entries
        """
        if reverse:
            rows = range(self.n_rows - 1, -1, -1)
            cols = range(self.n_cols - 1, -1, -1)
        else:
            rows, cols = range(self.n_rows), range(self.n_cols)
        if row_major:
            return (self._entries[r][c] for r in rows for c in cols)
        return (self._entries[r][c] for c in cols for r in rows)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…