We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Update Matrix to ensure consistency
## Motivation
<!-- Outline your motivation: In what way do your changes improve the library? -->
As described in #924, ```Matrix``` shows inconsistent behavior depending on whether ```DecimalNumber``` or ```MathTex``` is used as the underlying mobject. Additionally, passing a 1d row-vector results in a column-vector to be displayed (Note that while this is not a breaking change, it changes the visualization of existing code!).

Closes #924 



## Overview / Explanation for Changes
<!-- Give an overview of your changes and explain how they
resolve the situation described in the previous section.

For PRs introducing new features, please provide code snippets
using the newly introduced functionality and ideally even the
expected rendered output. -->

The following change addresses both points mentioned in the motivation.
```py
matrix = np.array(matrix, ndmin=1)
```
to
```py
matrix = np.array(matrix, ndmin=2)
```

The other change, which is the introduction of the ```transpose``` argument is for the following reason:
```py
from manim import *


class Test(Scene):
    def construct(self):
        arr = np.array([0.1, 0.3])
        # Transposing a vector does not do anything!
        m1 = DecimalMatrix(arr.transpose())
        self.add(m1)

        # Transposing a vector (remember ndmin=2 in matrix.py) now works!
        m2 = DecimalMatrix(arr, transpose=True).next_to(m1, DOWN)
        self.add(m2)

        self.wait(2)
```
Resulting image:
<img width="443" alt="Screenshot 2021-01-11 at 11 57 04" src="https://user-images.githubusercontent.com/22744609/104172306-5d7ce280-5404-11eb-9bec-ef8941b96951.png">


## Oneline Summary of Changes
```
- Ensure consistent matrix behavior (:pr:`925`)
```

## Testing Status
Just tested with the code above and a part of my codebase (consisting of around 6 different matrices)


## Acknowledgements
- [x] I have read the [Contributing Guidelines](https://docs.manim.community/en/latest/contributing.html)

<!-- Once again, thanks for helping out by contributing to manim! -->


<!-- Do not modify the lines below. -->
## Reviewer Checklist
- [ ] Newly added functions/classes are either private or have a docstring
- [ ] Newly added functions/classes have [tests](https://github.com/ManimCommunity/manim/wiki/Testing) added and (optional) examples in the docs
- [ ] Newly added documentation builds, looks correctly formatted, and adds no additional build warnings
- [ ] The oneline summary has been included [in the wiki](https://github.com/ManimCommunity/manim/wiki/Changelog-for-next-release)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `manim/mobject/matrix.py`
Content:
```
1 """Mobjects representing matrices."""
2 
3 __all__ = [
4     "Matrix",
5     "DecimalMatrix",
6     "IntegerMatrix",
7     "MobjectMatrix",
8     "matrix_to_tex_string",
9     "matrix_to_mobject",
10     "vector_coordinate_label",
11     "get_det_text",
12 ]
13 
14 
15 import numpy as np
16 
17 from ..constants import *
18 from ..mobject.numbers import DecimalNumber
19 from ..mobject.numbers import Integer
20 from ..mobject.shape_matchers import BackgroundRectangle
21 from ..mobject.svg.tex_mobject import MathTex
22 from ..mobject.svg.tex_mobject import Tex
23 from ..mobject.types.vectorized_mobject import VGroup
24 from ..mobject.types.vectorized_mobject import VMobject
25 from ..utils.color import WHITE
26 
27 VECTOR_LABEL_SCALE_FACTOR = 0.8
28 
29 
30 def matrix_to_tex_string(matrix):
31     matrix = np.array(matrix).astype("str")
32     if matrix.ndim == 1:
33         matrix = matrix.reshape((matrix.size, 1))
34     n_rows, n_cols = matrix.shape
35     prefix = "\\left[ \\begin{array}{%s}" % ("c" * n_cols)
36     suffix = "\\end{array} \\right]"
37     rows = [" & ".join(row) for row in matrix]
38     return prefix + " \\\\ ".join(rows) + suffix
39 
40 
41 def matrix_to_mobject(matrix):
42     return MathTex(matrix_to_tex_string(matrix))
43 
44 
45 def vector_coordinate_label(vector_mob, integer_labels=True, n_dim=2, color=WHITE):
46     vect = np.array(vector_mob.get_end())
47     if integer_labels:
48         vect = np.round(vect).astype(int)
49     vect = vect[:n_dim]
50     vect = vect.reshape((n_dim, 1))
51     label = Matrix(vect, add_background_rectangles_to_entries=True)
52     label.scale(VECTOR_LABEL_SCALE_FACTOR)
53 
54     shift_dir = np.array(vector_mob.get_end())
55     if shift_dir[0] >= 0:  # Pointing right
56         shift_dir -= label.get_left() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * LEFT
57     else:  # Pointing left
58         shift_dir -= label.get_right() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * RIGHT
59     label.shift(shift_dir)
60     label.set_color(color)
61     label.rect = BackgroundRectangle(label)
62     label.add_to_back(label.rect)
63     return label
64 
65 
66 class Matrix(VMobject):
67     def __init__(
68         self,
69         matrix,
70         v_buff=0.8,
71         h_buff=1.3,
72         bracket_h_buff=MED_SMALL_BUFF,
73         bracket_v_buff=MED_SMALL_BUFF,
74         add_background_rectangles_to_entries=False,
75         include_background_rectangle=False,
76         element_to_mobject=MathTex,
77         element_to_mobject_config={},
78         element_alignment_corner=DR,
79         left_bracket="\\big[",
80         right_bracket="\\big]",
81         **kwargs
82     ):
83         """
84         Matrix can either either include numbers, tex_strings,
85         or mobjects
86         """
87         self.v_buff = v_buff
88         self.h_buff = h_buff
89         self.bracket_h_buff = bracket_h_buff
90         self.bracket_v_buff = bracket_v_buff
91         self.add_background_rectangles_to_entries = add_background_rectangles_to_entries
92         self.include_background_rectangle = include_background_rectangle
93         self.element_to_mobject = element_to_mobject
94         self.element_to_mobject_config = element_to_mobject_config
95         self.element_alignment_corner = element_alignment_corner
96         self.left_bracket = left_bracket
97         self.right_bracket = right_bracket
98         VMobject.__init__(self, **kwargs)
99         matrix = np.array(matrix, ndmin=1)
100         mob_matrix = self.matrix_to_mob_matrix(matrix)
101         self.organize_mob_matrix(mob_matrix)
102         self.elements = VGroup(*mob_matrix.flatten())
103         self.add(self.elements)
104         self.add_brackets(self.left_bracket, self.right_bracket)
105         self.center()
106         self.mob_matrix = mob_matrix
107         if self.add_background_rectangles_to_entries:
108             for mob in self.elements:
109                 mob.add_background_rectangle()
110         if self.include_background_rectangle:
111             self.add_background_rectangle()
112 
113     def matrix_to_mob_matrix(self, matrix):
114         return np.vectorize(self.element_to_mobject)(
115             matrix, **self.element_to_mobject_config
116         )
117 
118     def organize_mob_matrix(self, matrix):
119         for i, row in enumerate(matrix):
120             for j, elem in enumerate(row):
121                 mob = matrix[i][j]
122                 mob.move_to(
123                     i * self.v_buff * DOWN + j * self.h_buff * RIGHT,
124                     self.element_alignment_corner,
125                 )
126         return self
127 
128     def add_brackets(self, left="\\big[", right="\\big]"):
129         bracket_pair = MathTex(left, right)
130         bracket_pair.scale(2)
131         bracket_pair.stretch_to_fit_height(self.get_height() + 2 * self.bracket_v_buff)
132         l_bracket, r_bracket = bracket_pair.split()
133         l_bracket.next_to(self, LEFT, self.bracket_h_buff)
134         r_bracket.next_to(self, RIGHT, self.bracket_h_buff)
135         self.add(l_bracket, r_bracket)
136         self.brackets = VGroup(l_bracket, r_bracket)
137         return self
138 
139     def get_columns(self):
140         return VGroup(
141             *[VGroup(*self.mob_matrix[:, i]) for i in range(self.mob_matrix.shape[1])]
142         )
143 
144     def set_column_colors(self, *colors):
145         columns = self.get_columns()
146         for color, column in zip(colors, columns):
147             column.set_color(color)
148         return self
149 
150     def get_rows(self):
151         """Return rows of the matrix as VGroups
152 
153         Returns
154         --------
155         List[:class:`~.VGroup`]
156             Each VGroup contains a row of the matrix.
157         """
158         return VGroup(
159             *[VGroup(*self.mob_matrix[i, :]) for i in range(self.mob_matrix.shape[0])]
160         )
161 
162     def set_row_colors(self, *colors):
163         """Set individual colors for each row of the matrix
164 
165         Parameters
166         ----------
167         colors : :class:`str`
168             The list of colors; each color specified corresponds to a row.
169 
170         Returns
171         -------
172         :class:`Matrix`
173             The current matrix object (self).
174         """
175         rows = self.get_rows()
176         for color, row in zip(colors, rows):
177             row.set_color(color)
178         return self
179 
180     def add_background_to_entries(self):
181         for mob in self.get_entries():
182             mob.add_background_rectangle()
183         return self
184 
185     def get_mob_matrix(self):
186         return self.mob_matrix
187 
188     def get_entries(self):
189         return VGroup(*self.get_mob_matrix().flatten())
190 
191     def get_brackets(self):
192         return self.brackets
193 
194 
195 class DecimalMatrix(Matrix):
196     def __init__(
197         self,
198         matrix,
199         element_to_mobject=DecimalNumber,
200         element_to_mobject_config={"num_decimal_places": 1},
201         **kwargs
202     ):
203         Matrix.__init__(
204             self,
205             matrix,
206             element_to_mobject=element_to_mobject,
207             element_to_mobject_config=element_to_mobject_config,
208             **kwargs
209         )
210 
211 
212 class IntegerMatrix(Matrix):
213     def __init__(self, matrix, element_to_mobject=Integer, **kwargs):
214         Matrix.__init__(self, matrix, element_to_mobject=element_to_mobject, **kwargs)
215 
216 
217 class MobjectMatrix(Matrix):
218     def __init__(self, matrix, element_to_mobject=lambda m: m, **kwargs):
219         Matrix.__init__(self, matrix, element_to_mobject=element_to_mobject, **kwargs)
220 
221 
222 def get_det_text(
223     matrix, determinant=None, background_rect=False, initial_scale_factor=2
224 ):
225     parens = MathTex("(", ")")
226     parens.scale(initial_scale_factor)
227     parens.stretch_to_fit_height(matrix.get_height())
228     l_paren, r_paren = parens.split()
229     l_paren.next_to(matrix, LEFT, buff=0.1)
230     r_paren.next_to(matrix, RIGHT, buff=0.1)
231     det = Tex("det")
232     det.scale(initial_scale_factor)
233     det.next_to(l_paren, LEFT, buff=0.1)
234     if background_rect:
235         det.add_background_rectangle()
236     det_text = VGroup(det, l_paren, r_paren)
237     if determinant is not None:
238         eq = MathTex("=")
239         eq.next_to(r_paren, RIGHT, buff=0.1)
240         result = MathTex(str(determinant))
241         result.next_to(eq, RIGHT, buff=0.2)
242         det_text.add(eq, result)
243     return det_text
244
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/manim/mobject/matrix.py b/manim/mobject/matrix.py
--- a/manim/mobject/matrix.py
+++ b/manim/mobject/matrix.py
@@ -78,7 +78,7 @@
         element_alignment_corner=DR,
         left_bracket="\\big[",
         right_bracket="\\big]",
-        **kwargs
+        **kwargs,
     ):
         """
         Matrix can either either include numbers, tex_strings,
@@ -96,7 +96,11 @@
         self.left_bracket = left_bracket
         self.right_bracket = right_bracket
         VMobject.__init__(self, **kwargs)
-        matrix = np.array(matrix, ndmin=1)
+        if len(matrix.shape) < 2:
+            raise ValueError(
+                f"{self.__str__()} class requires a two-dimensional array!"
+            )
+        matrix = np.array(matrix)
         mob_matrix = self.matrix_to_mob_matrix(matrix)
         self.organize_mob_matrix(mob_matrix)
         self.elements = VGroup(*mob_matrix.flatten())
@@ -198,14 +202,14 @@
         matrix,
         element_to_mobject=DecimalNumber,
         element_to_mobject_config={"num_decimal_places": 1},
-        **kwargs
+        **kwargs,
     ):
         Matrix.__init__(
             self,
             matrix,
             element_to_mobject=element_to_mobject,
             element_to_mobject_config=element_to_mobject_config,
-            **kwargs
+            **kwargs,
         )

{"golden_diff": "diff --git a/manim/mobject/matrix.py b/manim/mobject/matrix.py\n--- a/manim/mobject/matrix.py\n+++ b/manim/mobject/matrix.py\n@@ -78,7 +78,7 @@\n         element_alignment_corner=DR,\n         left_bracket=\"\\\\big[\",\n         right_bracket=\"\\\\big]\",\n-        **kwargs\n+        **kwargs,\n     ):\n         \"\"\"\n         Matrix can either either include numbers, tex_strings,\n@@ -96,7 +96,11 @@\n         self.left_bracket = left_bracket\n         self.right_bracket = right_bracket\n         VMobject.__init__(self, **kwargs)\n-        matrix = np.array(matrix, ndmin=1)\n+        if len(matrix.shape) < 2:\n+            raise ValueError(\n+                f\"{self.__str__()} class requires a two-dimensional array!\"\n+            )\n+        matrix = np.array(matrix)\n         mob_matrix = self.matrix_to_mob_matrix(matrix)\n         self.organize_mob_matrix(mob_matrix)\n         self.elements = VGroup(*mob_matrix.flatten())\n@@ -198,14 +202,14 @@\n         matrix,\n         element_to_mobject=DecimalNumber,\n         element_to_mobject_config={\"num_decimal_places\": 1},\n-        **kwargs\n+        **kwargs,\n     ):\n         Matrix.__init__(\n             self,\n             matrix,\n             element_to_mobject=element_to_mobject,\n             element_to_mobject_config=element_to_mobject_config,\n-            **kwargs\n+            **kwargs,\n         )\n", "issue": "Update Matrix to ensure consistency\n## Motivation\r\n<!-- Outline your motivation: In what way do your changes improve the library? -->\r\nAs described in #924, ```Matrix``` shows inconsistent behavior depending on whether ```DecimalNumber``` or ```MathTex``` is used as the underlying mobject. Additionally, passing a 1d row-vector results in a column-vector to be displayed (Note that while this is not a breaking change, it changes the visualization of existing code!).\r\n\r\nCloses #924 \r\n\r\n\r\n\r\n## Overview / Explanation for Changes\r\n<!-- Give an overview of your changes and explain how they\r\nresolve the situation described in the previous section.\r\n\r\nFor PRs introducing new features, please provide code snippets\r\nusing the newly introduced functionality and ideally even the\r\nexpected rendered output. -->\r\n\r\nThe following change addresses both points mentioned in the motivation.\r\n```py\r\nmatrix = np.array(matrix, ndmin=1)\r\n```\r\nto\r\n```py\r\nmatrix = np.array(matrix, ndmin=2)\r\n```\r\n\r\nThe other change, which is the introduction of the ```transpose``` argument is for the following reason:\r\n```py\r\nfrom manim import *\r\n\r\n\r\nclass Test(Scene):\r\n    def construct(self):\r\n        arr = np.array([0.1, 0.3])\r\n        # Transposing a vector does not do anything!\r\n        m1 = DecimalMatrix(arr.transpose())\r\n        self.add(m1)\r\n\r\n        # Transposing a vector (remember ndmin=2 in matrix.py) now works!\r\n        m2 = DecimalMatrix(arr, transpose=True).next_to(m1, DOWN)\r\n        self.add(m2)\r\n\r\n        self.wait(2)\r\n```\r\nResulting image:\r\n<img width=\"443\" alt=\"Screenshot 2021-01-11 at 11 57 04\" src=\"https://user-images.githubusercontent.com/22744609/104172306-5d7ce280-5404-11eb-9bec-ef8941b96951.png\">\r\n\r\n\r\n## Oneline Summary of Changes\r\n```\r\n- Ensure consistent matrix behavior (:pr:`925`)\r\n```\r\n\r\n## Testing Status\r\nJust tested with the code above and a part of my codebase (consisting of around 6 different matrices)\r\n\r\n\r\n## Acknowledgements\r\n- [x] I have read the [Contributing Guidelines](https://docs.manim.community/en/latest/contributing.html)\r\n\r\n<!-- Once again, thanks for helping out by contributing to manim! -->\r\n\r\n\r\n<!-- Do not modify the lines below. -->\r\n## Reviewer Checklist\r\n- [ ] Newly added functions/classes are either private or have a docstring\r\n- [ ] Newly added functions/classes have [tests](https://github.com/ManimCommunity/manim/wiki/Testing) added and (optional) examples in the docs\r\n- [ ] Newly added documentation builds, looks correctly formatted, and adds no additional build warnings\r\n- [ ] The oneline summary has been included [in the wiki](https://github.com/ManimCommunity/manim/wiki/Changelog-for-next-release)\r\n\n", "before_files": [{"content": "\"\"\"Mobjects representing matrices.\"\"\"\n\n__all__ = [\n    \"Matrix\",\n    \"DecimalMatrix\",\n    \"IntegerMatrix\",\n    \"MobjectMatrix\",\n    \"matrix_to_tex_string\",\n    \"matrix_to_mobject\",\n    \"vector_coordinate_label\",\n    \"get_det_text\",\n]\n\n\nimport numpy as np\n\nfrom ..constants import *\nfrom ..mobject.numbers import DecimalNumber\nfrom ..mobject.numbers import Integer\nfrom ..mobject.shape_matchers import BackgroundRectangle\nfrom ..mobject.svg.tex_mobject import MathTex\nfrom ..mobject.svg.tex_mobject import Tex\nfrom ..mobject.types.vectorized_mobject import VGroup\nfrom ..mobject.types.vectorized_mobject import VMobject\nfrom ..utils.color import WHITE\n\nVECTOR_LABEL_SCALE_FACTOR = 0.8\n\n\ndef matrix_to_tex_string(matrix):\n    matrix = np.array(matrix).astype(\"str\")\n    if matrix.ndim == 1:\n        matrix = matrix.reshape((matrix.size, 1))\n    n_rows, n_cols = matrix.shape\n    prefix = \"\\\\left[ \\\\begin{array}{%s}\" % (\"c\" * n_cols)\n    suffix = \"\\\\end{array} \\\\right]\"\n    rows = [\" & \".join(row) for row in matrix]\n    return prefix + \" \\\\\\\\ \".join(rows) + suffix\n\n\ndef matrix_to_mobject(matrix):\n    return MathTex(matrix_to_tex_string(matrix))\n\n\ndef vector_coordinate_label(vector_mob, integer_labels=True, n_dim=2, color=WHITE):\n    vect = np.array(vector_mob.get_end())\n    if integer_labels:\n        vect = np.round(vect).astype(int)\n    vect = vect[:n_dim]\n    vect = vect.reshape((n_dim, 1))\n    label = Matrix(vect, add_background_rectangles_to_entries=True)\n    label.scale(VECTOR_LABEL_SCALE_FACTOR)\n\n    shift_dir = np.array(vector_mob.get_end())\n    if shift_dir[0] >= 0:  # Pointing right\n        shift_dir -= label.get_left() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * LEFT\n    else:  # Pointing left\n        shift_dir -= label.get_right() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * RIGHT\n    label.shift(shift_dir)\n    label.set_color(color)\n    label.rect = BackgroundRectangle(label)\n    label.add_to_back(label.rect)\n    return label\n\n\nclass Matrix(VMobject):\n    def __init__(\n        self,\n        matrix,\n        v_buff=0.8,\n        h_buff=1.3,\n        bracket_h_buff=MED_SMALL_BUFF,\n        bracket_v_buff=MED_SMALL_BUFF,\n        add_background_rectangles_to_entries=False,\n        include_background_rectangle=False,\n        element_to_mobject=MathTex,\n        element_to_mobject_config={},\n        element_alignment_corner=DR,\n        left_bracket=\"\\\\big[\",\n        right_bracket=\"\\\\big]\",\n        **kwargs\n    ):\n        \"\"\"\n        Matrix can either either include numbers, tex_strings,\n        or mobjects\n        \"\"\"\n        self.v_buff = v_buff\n        self.h_buff = h_buff\n        self.bracket_h_buff = bracket_h_buff\n        self.bracket_v_buff = bracket_v_buff\n        self.add_background_rectangles_to_entries = add_background_rectangles_to_entries\n        self.include_background_rectangle = include_background_rectangle\n        self.element_to_mobject = element_to_mobject\n        self.element_to_mobject_config = element_to_mobject_config\n        self.element_alignment_corner = element_alignment_corner\n        self.left_bracket = left_bracket\n        self.right_bracket = right_bracket\n        VMobject.__init__(self, **kwargs)\n        matrix = np.array(matrix, ndmin=1)\n        mob_matrix = self.matrix_to_mob_matrix(matrix)\n        self.organize_mob_matrix(mob_matrix)\n        self.elements = VGroup(*mob_matrix.flatten())\n        self.add(self.elements)\n        self.add_brackets(self.left_bracket, self.right_bracket)\n        self.center()\n        self.mob_matrix = mob_matrix\n        if self.add_background_rectangles_to_entries:\n            for mob in self.elements:\n                mob.add_background_rectangle()\n        if self.include_background_rectangle:\n            self.add_background_rectangle()\n\n    def matrix_to_mob_matrix(self, matrix):\n        return np.vectorize(self.element_to_mobject)(\n            matrix, **self.element_to_mobject_config\n        )\n\n    def organize_mob_matrix(self, matrix):\n        for i, row in enumerate(matrix):\n            for j, elem in enumerate(row):\n                mob = matrix[i][j]\n                mob.move_to(\n                    i * self.v_buff * DOWN + j * self.h_buff * RIGHT,\n                    self.element_alignment_corner,\n                )\n        return self\n\n    def add_brackets(self, left=\"\\\\big[\", right=\"\\\\big]\"):\n        bracket_pair = MathTex(left, right)\n        bracket_pair.scale(2)\n        bracket_pair.stretch_to_fit_height(self.get_height() + 2 * self.bracket_v_buff)\n        l_bracket, r_bracket = bracket_pair.split()\n        l_bracket.next_to(self, LEFT, self.bracket_h_buff)\n        r_bracket.next_to(self, RIGHT, self.bracket_h_buff)\n        self.add(l_bracket, r_bracket)\n        self.brackets = VGroup(l_bracket, r_bracket)\n        return self\n\n    def get_columns(self):\n        return VGroup(\n            *[VGroup(*self.mob_matrix[:, i]) for i in range(self.mob_matrix.shape[1])]\n        )\n\n    def set_column_colors(self, *colors):\n        columns = self.get_columns()\n        for color, column in zip(colors, columns):\n            column.set_color(color)\n        return self\n\n    def get_rows(self):\n        \"\"\"Return rows of the matrix as VGroups\n\n        Returns\n        --------\n        List[:class:`~.VGroup`]\n            Each VGroup contains a row of the matrix.\n        \"\"\"\n        return VGroup(\n            *[VGroup(*self.mob_matrix[i, :]) for i in range(self.mob_matrix.shape[0])]\n        )\n\n    def set_row_colors(self, *colors):\n        \"\"\"Set individual colors for each row of the matrix\n\n        Parameters\n        ----------\n        colors : :class:`str`\n            The list of colors; each color specified corresponds to a row.\n\n        Returns\n        -------\n        :class:`Matrix`\n            The current matrix object (self).\n        \"\"\"\n        rows = self.get_rows()\n        for color, row in zip(colors, rows):\n            row.set_color(color)\n        return self\n\n    def add_background_to_entries(self):\n        for mob in self.get_entries():\n            mob.add_background_rectangle()\n        return self\n\n    def get_mob_matrix(self):\n        return self.mob_matrix\n\n    def get_entries(self):\n        return VGroup(*self.get_mob_matrix().flatten())\n\n    def get_brackets(self):\n        return self.brackets\n\n\nclass DecimalMatrix(Matrix):\n    def __init__(\n        self,\n        matrix,\n        element_to_mobject=DecimalNumber,\n        element_to_mobject_config={\"num_decimal_places\": 1},\n        **kwargs\n    ):\n        Matrix.__init__(\n            self,\n            matrix,\n            element_to_mobject=element_to_mobject,\n            element_to_mobject_config=element_to_mobject_config,\n            **kwargs\n        )\n\n\nclass IntegerMatrix(Matrix):\n    def __init__(self, matrix, element_to_mobject=Integer, **kwargs):\n        Matrix.__init__(self, matrix, element_to_mobject=element_to_mobject, **kwargs)\n\n\nclass MobjectMatrix(Matrix):\n    def __init__(self, matrix, element_to_mobject=lambda m: m, **kwargs):\n        Matrix.__init__(self, matrix, element_to_mobject=element_to_mobject, **kwargs)\n\n\ndef get_det_text(\n    matrix, determinant=None, background_rect=False, initial_scale_factor=2\n):\n    parens = MathTex(\"(\", \")\")\n    parens.scale(initial_scale_factor)\n    parens.stretch_to_fit_height(matrix.get_height())\n    l_paren, r_paren = parens.split()\n    l_paren.next_to(matrix, LEFT, buff=0.1)\n    r_paren.next_to(matrix, RIGHT, buff=0.1)\n    det = Tex(\"det\")\n    det.scale(initial_scale_factor)\n    det.next_to(l_paren, LEFT, buff=0.1)\n    if background_rect:\n        det.add_background_rectangle()\n    det_text = VGroup(det, l_paren, r_paren)\n    if determinant is not None:\n        eq = MathTex(\"=\")\n        eq.next_to(r_paren, RIGHT, buff=0.1)\n        result = MathTex(str(determinant))\n        result.next_to(eq, RIGHT, buff=0.2)\n        det_text.add(eq, result)\n    return det_text\n", "path": "manim/mobject/matrix.py"}], "after_files": [{"content": "\"\"\"Mobjects representing matrices.\"\"\"\n\n__all__ = [\n    \"Matrix\",\n    \"DecimalMatrix\",\n    \"IntegerMatrix\",\n    \"MobjectMatrix\",\n    \"matrix_to_tex_string\",\n    \"matrix_to_mobject\",\n    \"vector_coordinate_label\",\n    \"get_det_text\",\n]\n\n\nimport numpy as np\n\nfrom ..constants import *\nfrom ..mobject.numbers import DecimalNumber\nfrom ..mobject.numbers import Integer\nfrom ..mobject.shape_matchers import BackgroundRectangle\nfrom ..mobject.svg.tex_mobject import MathTex\nfrom ..mobject.svg.tex_mobject import Tex\nfrom ..mobject.types.vectorized_mobject import VGroup\nfrom ..mobject.types.vectorized_mobject import VMobject\nfrom ..utils.color import WHITE\n\nVECTOR_LABEL_SCALE_FACTOR = 0.8\n\n\ndef matrix_to_tex_string(matrix):\n    matrix = np.array(matrix).astype(\"str\")\n    if matrix.ndim == 1:\n        matrix = matrix.reshape((matrix.size, 1))\n    n_rows, n_cols = matrix.shape\n    prefix = \"\\\\left[ \\\\begin{array}{%s}\" % (\"c\" * n_cols)\n    suffix = \"\\\\end{array} \\\\right]\"\n    rows = [\" & \".join(row) for row in matrix]\n    return prefix + \" \\\\\\\\ \".join(rows) + suffix\n\n\ndef matrix_to_mobject(matrix):\n    return MathTex(matrix_to_tex_string(matrix))\n\n\ndef vector_coordinate_label(vector_mob, integer_labels=True, n_dim=2, color=WHITE):\n    vect = np.array(vector_mob.get_end())\n    if integer_labels:\n        vect = np.round(vect).astype(int)\n    vect = vect[:n_dim]\n    vect = vect.reshape((n_dim, 1))\n    label = Matrix(vect, add_background_rectangles_to_entries=True)\n    label.scale(VECTOR_LABEL_SCALE_FACTOR)\n\n    shift_dir = np.array(vector_mob.get_end())\n    if shift_dir[0] >= 0:  # Pointing right\n        shift_dir -= label.get_left() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * LEFT\n    else:  # Pointing left\n        shift_dir -= label.get_right() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * RIGHT\n    label.shift(shift_dir)\n    label.set_color(color)\n    label.rect = BackgroundRectangle(label)\n    label.add_to_back(label.rect)\n    return label\n\n\nclass Matrix(VMobject):\n    def __init__(\n        self,\n        matrix,\n        v_buff=0.8,\n        h_buff=1.3,\n        bracket_h_buff=MED_SMALL_BUFF,\n        bracket_v_buff=MED_SMALL_BUFF,\n        add_background_rectangles_to_entries=False,\n        include_background_rectangle=False,\n        element_to_mobject=MathTex,\n        element_to_mobject_config={},\n        element_alignment_corner=DR,\n        left_bracket=\"\\\\big[\",\n        right_bracket=\"\\\\big]\",\n        **kwargs,\n    ):\n        \"\"\"\n        Matrix can either either include numbers, tex_strings,\n        or mobjects\n        \"\"\"\n        self.v_buff = v_buff\n        self.h_buff = h_buff\n        self.bracket_h_buff = bracket_h_buff\n        self.bracket_v_buff = bracket_v_buff\n        self.add_background_rectangles_to_entries = add_background_rectangles_to_entries\n        self.include_background_rectangle = include_background_rectangle\n        self.element_to_mobject = element_to_mobject\n        self.element_to_mobject_config = element_to_mobject_config\n        self.element_alignment_corner = element_alignment_corner\n        self.left_bracket = left_bracket\n        self.right_bracket = right_bracket\n        VMobject.__init__(self, **kwargs)\n        if len(matrix.shape) < 2:\n            raise ValueError(\n                f\"{self.__str__()} class requires a two-dimensional array!\"\n            )\n        matrix = np.array(matrix)\n        mob_matrix = self.matrix_to_mob_matrix(matrix)\n        self.organize_mob_matrix(mob_matrix)\n        self.elements = VGroup(*mob_matrix.flatten())\n        self.add(self.elements)\n        self.add_brackets(self.left_bracket, self.right_bracket)\n        self.center()\n        self.mob_matrix = mob_matrix\n        if self.add_background_rectangles_to_entries:\n            for mob in self.elements:\n                mob.add_background_rectangle()\n        if self.include_background_rectangle:\n            self.add_background_rectangle()\n\n    def matrix_to_mob_matrix(self, matrix):\n        return np.vectorize(self.element_to_mobject)(\n            matrix, **self.element_to_mobject_config\n        )\n\n    def organize_mob_matrix(self, matrix):\n        for i, row in enumerate(matrix):\n            for j, elem in enumerate(row):\n                mob = matrix[i][j]\n                mob.move_to(\n                    i * self.v_buff * DOWN + j * self.h_buff * RIGHT,\n                    self.element_alignment_corner,\n                )\n        return self\n\n    def add_brackets(self, left=\"\\\\big[\", right=\"\\\\big]\"):\n        bracket_pair = MathTex(left, right)\n        bracket_pair.scale(2)\n        bracket_pair.stretch_to_fit_height(self.get_height() + 2 * self.bracket_v_buff)\n        l_bracket, r_bracket = bracket_pair.split()\n        l_bracket.next_to(self, LEFT, self.bracket_h_buff)\n        r_bracket.next_to(self, RIGHT, self.bracket_h_buff)\n        self.add(l_bracket, r_bracket)\n        self.brackets = VGroup(l_bracket, r_bracket)\n        return self\n\n    def get_columns(self):\n        return VGroup(\n            *[VGroup(*self.mob_matrix[:, i]) for i in range(self.mob_matrix.shape[1])]\n        )\n\n    def set_column_colors(self, *colors):\n        columns = self.get_columns()\n        for color, column in zip(colors, columns):\n            column.set_color(color)\n        return self\n\n    def get_rows(self):\n        \"\"\"Return rows of the matrix as VGroups\n\n        Returns\n        --------\n        List[:class:`~.VGroup`]\n            Each VGroup contains a row of the matrix.\n        \"\"\"\n        return VGroup(\n            *[VGroup(*self.mob_matrix[i, :]) for i in range(self.mob_matrix.shape[0])]\n        )\n\n    def set_row_colors(self, *colors):\n        \"\"\"Set individual colors for each row of the matrix\n\n        Parameters\n        ----------\n        colors : :class:`str`\n            The list of colors; each color specified corresponds to a row.\n\n        Returns\n        -------\n        :class:`Matrix`\n            The current matrix object (self).\n        \"\"\"\n        rows = self.get_rows()\n        for color, row in zip(colors, rows):\n            row.set_color(color)\n        return self\n\n    def add_background_to_entries(self):\n        for mob in self.get_entries():\n            mob.add_background_rectangle()\n        return self\n\n    def get_mob_matrix(self):\n        return self.mob_matrix\n\n    def get_entries(self):\n        return VGroup(*self.get_mob_matrix().flatten())\n\n    def get_brackets(self):\n        return self.brackets\n\n\nclass DecimalMatrix(Matrix):\n    def __init__(\n        self,\n        matrix,\n        element_to_mobject=DecimalNumber,\n        element_to_mobject_config={\"num_decimal_places\": 1},\n        **kwargs,\n    ):\n        Matrix.__init__(\n            self,\n            matrix,\n            element_to_mobject=element_to_mobject,\n            element_to_mobject_config=element_to_mobject_config,\n            **kwargs,\n        )\n\n\nclass IntegerMatrix(Matrix):\n    def __init__(self, matrix, element_to_mobject=Integer, **kwargs):\n        Matrix.__init__(self, matrix, element_to_mobject=element_to_mobject, **kwargs)\n\n\nclass MobjectMatrix(Matrix):\n    def __init__(self, matrix, element_to_mobject=lambda m: m, **kwargs):\n        Matrix.__init__(self, matrix, element_to_mobject=element_to_mobject, **kwargs)\n\n\ndef get_det_text(\n    matrix, determinant=None, background_rect=False, initial_scale_factor=2\n):\n    parens = MathTex(\"(\", \")\")\n    parens.scale(initial_scale_factor)\n    parens.stretch_to_fit_height(matrix.get_height())\n    l_paren, r_paren = parens.split()\n    l_paren.next_to(matrix, LEFT, buff=0.1)\n    r_paren.next_to(matrix, RIGHT, buff=0.1)\n    det = Tex(\"det\")\n    det.scale(initial_scale_factor)\n    det.next_to(l_paren, LEFT, buff=0.1)\n    if background_rect:\n        det.add_background_rectangle()\n    det_text = VGroup(det, l_paren, r_paren)\n    if determinant is not None:\n        eq = MathTex(\"=\")\n        eq.next_to(r_paren, RIGHT, buff=0.1)\n        result = MathTex(str(determinant))\n        result.next_to(eq, RIGHT, buff=0.2)\n        det_text.add(eq, result)\n    return det_text\n", "path": "manim/mobject/matrix.py"}]}