mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Treat Matrix.mob_matrix as list rather than numpy matrix, since it sometimes interprets mobjects as sequences
This commit is contained in:
parent
d65a915e7b
commit
2e3a112ff8
1 changed files with 13 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import itertools as it
|
||||||
|
|
||||||
from manimlib.constants import *
|
from manimlib.constants import *
|
||||||
from manimlib.mobject.numbers import DecimalNumber
|
from manimlib.mobject.numbers import DecimalNumber
|
||||||
|
@ -74,7 +75,8 @@ class Matrix(VMobject):
|
||||||
matrix = self.matrix = np.array(matrix, ndmin=2)
|
matrix = self.matrix = np.array(matrix, ndmin=2)
|
||||||
mob_matrix = self.matrix_to_mob_matrix(matrix)
|
mob_matrix = self.matrix_to_mob_matrix(matrix)
|
||||||
self.organize_mob_matrix(mob_matrix)
|
self.organize_mob_matrix(mob_matrix)
|
||||||
self.elements = VGroup(*mob_matrix.flatten())
|
# self.elements = VGroup(*mob_matrix.flatten())
|
||||||
|
self.elements = VGroup(*it.chain(*mob_matrix))
|
||||||
self.add(self.elements)
|
self.add(self.elements)
|
||||||
self.add_brackets()
|
self.add_brackets()
|
||||||
self.center()
|
self.center()
|
||||||
|
@ -86,9 +88,13 @@ class Matrix(VMobject):
|
||||||
self.add_background_rectangle()
|
self.add_background_rectangle()
|
||||||
|
|
||||||
def matrix_to_mob_matrix(self, matrix):
|
def matrix_to_mob_matrix(self, matrix):
|
||||||
return np.vectorize(self.element_to_mobject)(
|
return [
|
||||||
matrix, **self.element_to_mobject_config
|
[
|
||||||
)
|
self.element_to_mobject(item, **self.element_to_mobject_config)
|
||||||
|
for item in row
|
||||||
|
]
|
||||||
|
for row in matrix
|
||||||
|
]
|
||||||
|
|
||||||
def organize_mob_matrix(self, matrix):
|
def organize_mob_matrix(self, matrix):
|
||||||
for i, row in enumerate(matrix):
|
for i, row in enumerate(matrix):
|
||||||
|
@ -122,8 +128,8 @@ class Matrix(VMobject):
|
||||||
|
|
||||||
def get_columns(self):
|
def get_columns(self):
|
||||||
return VGroup(*[
|
return VGroup(*[
|
||||||
VGroup(*self.mob_matrix[:, i])
|
VGroup(*[row[i] for row in self.mob_matrix])
|
||||||
for i in range(self.mob_matrix.shape[1])
|
for i in range(len(self.mob_matrix[0]))
|
||||||
])
|
])
|
||||||
|
|
||||||
def set_column_colors(self, *colors):
|
def set_column_colors(self, *colors):
|
||||||
|
@ -141,7 +147,7 @@ class Matrix(VMobject):
|
||||||
return self.mob_matrix
|
return self.mob_matrix
|
||||||
|
|
||||||
def get_entries(self):
|
def get_entries(self):
|
||||||
return VGroup(*self.get_mob_matrix().flatten())
|
return self.elements
|
||||||
|
|
||||||
def get_brackets(self):
|
def get_brackets(self):
|
||||||
return self.brackets
|
return self.brackets
|
||||||
|
|
Loading…
Add table
Reference in a new issue