Ejemplo n.º 1
0
 def three(self):
     res = NumMatrix()
     one = NumMatrix()
     res.full(2, 6, 3)
     one.full(3, 4, 0)
     two = Matrix()
     two.full(3, 2, 3)
     one.__putr(two)
     three = NumMatrix()
     three.full(2, 6, 3)
     four = NumMatrix()
     four.full(3, 4, 0)
     five = Matrix()
     five.full(3, 2, 3)
     four.__putr(five)
     six = NumMatrix()
     six.full(2, 6, 3)
     res.__putd(one)
     res.__putd(three)
     res.__putd(four)
     res.__putd(six)
     empty = Matrix()
     empty.full(12, 1, 0)
     res.__putr(empty)
     for i in range(len(res.matrix)):
         for j in range(len(res.matrix[0])):
             if res.matrix[i][j] == 0:
                 res.matrix[i][j] = ' '
     self.matrix = res.matrix
Ejemplo n.º 2
0
 def nine(self):
     res = NumMatrix()
     res.full(2, 6, 9)
     one = NumMatrix()
     one.full(3, 2, 9)
     two = Matrix()
     two.full(3, 2, 0)
     three = one.copy
     one.__putr(two)
     one.__putr(three)
     four = NumMatrix()
     four.full(2, 6, 9)
     five = NumMatrix()
     five.full(3, 4, 0)
     six = Matrix()
     six.full(3, 2, 9)
     five.__putr(six)
     seven = res.copy
     res.__putd(one)
     res.__putd(four)
     res.__putd(five)
     res.__putd(seven)
     empty = Matrix()
     empty.full(12, 1, 0)
     res.__putr(empty)
     for i in range(len(res.matrix)):
         for j in range(len(res.matrix[0])):
             if res.matrix[i][j] == 0:
                 res.matrix[i][j] = ' '
     self.matrix = res.matrix
Ejemplo n.º 3
0
 def four(self):
     res = NumMatrix()
     res.full(5, 2, 4)
     one = Matrix()
     one.full(5, 2, 0)
     two = res.copy
     res.__putr(one)
     res.__putr(two)
     three = NumMatrix()
     three.full(2, 6, 4)
     four = NumMatrix()
     four.full(5, 4, 0)
     five = Matrix()
     five.full(5, 2, 4)
     four.__putr(five)
     empty = Matrix()
     empty.full(12, 1, 0)
     res.__putd(three)
     res.__putd(four)
     res.__putr(empty)
     for i in range(len(res.matrix)):
         for j in range(len(res.matrix[0])):
             if res.matrix[i][j] == 0:
                 res.matrix[i][j] = ' '
     self.matrix = res.matrix
Ejemplo n.º 4
0
def get_theta(m, x1, x2, y):
    t = Matrix(m, 3, fill=1)
    for i in range(0, m):
        t[i][1] = x1[i]
        t[i][2] = x2[i]

    k = Matrix(m, 1, fill=0)
    for i in range(0, m):
        k[i][0] = y[i]

    return ((t.trans() * t).inv()) * t.trans() * k
Ejemplo n.º 5
0
 def one(self):
     res = NumMatrix()
     one = Matrix()
     empty = Matrix()
     res.full(12, 4, 0)
     one.full(12, 2, 1)
     empty.full(12, 1, 0)
     res.__putr(one)
     res.__putr(empty)
     for i in range(len(res.matrix)):
         for j in range(len(res.matrix[0])):
             if res.matrix[i][j] == 0:
                 res.matrix[i][j] = ' '
     self.matrix = res.matrix
Ejemplo n.º 6
0
def instanMatriz():
    global matrices, matrizActual, nombreActual
    #print(matrizActual)
    print(matrizActual)
    matriz = Matrix(matrizActual)
    #print(matriz)
    matrices[nombreActual] = matriz
Ejemplo n.º 7
0
 def seven(self):
     res = NumMatrix()
     res.full(2, 6, 7)
     one = NumMatrix()
     one.full(10, 4, 0)
     two = Matrix()
     two.full(10, 2, 7)
     one.__putr(two)
     empty = Matrix()
     empty.full(12, 1, 0)
     res.__putd(one)
     res.__putr(empty)
     for i in range(len(res.matrix)):
         for j in range(len(res.matrix[0])):
             if res.matrix[i][j] == 0:
                 res.matrix[i][j] = ' '
     self.matrix = res.matrix
Ejemplo n.º 8
0
 def get_shadow(self, board):
     self.shadow = Matrix()
     self.shadow.square(len(board) + 2, full=0)
     for i in range(len(board)):
         for j in range(len(board)):
             if board.matrix[i][j] != 0:
                 for k in range(3):
                     self.shadow.matrix[i][j + k] += 1
                     self.shadow.matrix[i + 1][j + k] += 1
                     self.shadow.matrix[i + 2][j + k] += 1
Ejemplo n.º 9
0
 def __init__(self, N):
     self.shadow = None
     self.checkerboard = None
     self.boomlist = []
     m = Matrix()
     if N == 'easy':
         m.full(8, 8, u'■')
         self.print = m.copy
         self.creat_matrix(8, 10)
     self.run()
Ejemplo n.º 10
0
 def creat_matrix(self, de, boomnum):
     m = Matrix()
     temp = []
     for i in range(de**2):
         temp.append(0)
     for i in range(boomnum):
         index = random.randint(0, de**2 - 1)
         temp[index] = 1
     m.square(de, temp)
     self.checkerboard = m.copy
Ejemplo n.º 11
0
def open_csv(path, header=None):
    matrix = Matrix()
    if header is None:
        pds = read_csv(path, header=None)
    else:
        pds = read_csv(path, header=header)
    temp = []
    for i in range(len(pds)):
        temp.append(pds.loc[i])
    matrix.get_matrix(temp)
    return matrix
Ejemplo n.º 12
0
 def love(num, printer=None):
     lover = MagicMatrix()
     op = assistfuction.Functions()
     one = Spmatrix()
     one.uper_ting(3, model=3)
     two = Matrix([[1], [1], [1]])
     three = Matrix([[0, 0, 0], [1, 0, 1], [1, 1, 1]])
     five = Spmatrix()
     five.uper_ting(3, model=2)
     five.T
     lover.get_matrix(op.split_matrix(one))
     lover.__putr(two)
     lover.__putr(three)
     lover.__putr(two)
     lover.__putr(five)
     add = Matrix()
     add.full(num, 11, 1)
     lover.__putd(add)
     six = Spmatrix()
     six.uper_ting(5, model=2)
     seven = Matrix([[1], [1], [1], [1], [1]])
     eight = Spmatrix()
     eight.uper_ting(5, model=1)
     eight.T
     temp2 = MagicMatrix()
     temp2.get_matrix(op.split_matrix(six))
     temp2.__putr(seven)
     temp2.__putr(eight)
     lover.__putd(temp2)
     end = Matrix([[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]])
     lover.__putd(end)
     for i in range(len(lover.matrix)):
         for j in range(len(lover.matrix[0])):
             if lover.matrix[i][j] == 0:
                 lover.matrix[i][j] = ' '
             else:
                 lover.matrix[i][j] = u'♥'
     if printer is not None:
         print('\033[31m', lover, '\033[0m')
     return lover.copy
Ejemplo n.º 13
0
 def zero(self):
     res = NumMatrix()
     res.full(2, 6, 1)
     one = NumMatrix()
     one.full(8, 2, 1)
     two = Matrix()
     two.full(8, 2, 0)
     three = one.copy
     one.__putr(two)
     one.__putr(three)
     four = res.copy
     res.__putd(one)
     res.__putd(four)
     empty = Matrix()
     empty.full(12, 1, 0)
     res.__putr(empty)
     for i in range(len(res.matrix)):
         for j in range(len(res.matrix[0])):
             if res.matrix[i][j] == 0:
                 res.matrix[i][j] = ' '
             else:
                 res.matrix[i][j] = 0
     self.matrix = res.matrix
Ejemplo n.º 14
0
import numpy as np
from pymatrix import Matrix
from pymatrix import Spmatrix
from pymatrix import Operation
import random


class FeatureMatrix(Matrix):
    @staticmethod
    def create_rotation_matrix(dimension, p, q, theta, rou=3):
        matrix_origin = Spmatrix.diagonal(Spmatrix(), dimension, 1)
        matrix_origin.matrix[p][p] = round(np.cos(theta), rou)
        matrix_origin.matrix[p][q] = round(-np.sin(theta), rou)
        matrix_origin.matrix[q][p] = round(np.sin(theta), rou)
        matrix_origin.matrix[q][q] = round(np.cos(theta), rou)

        return matrix_origin


if __name__ == '__main__':
    l = []
    for i in range(5):
        l.append([])
        for j in range(5):
            l[i].append(random.randint(1, 10))
    m = Matrix(l)
    f = FeatureMatrix.create_rotation_matrix(5, 2, 1, 1.047)
    print(m)
    print(f)
    print(Operation.mul(m, f))
Ejemplo n.º 15
0
comando = StringVar()
E = Entry(
    root,
    relief=FLAT,
    highlightbackground="black",
    textvariable=comando,
    width=79,
    bd=0,
    bg="black",
    fg="white",
    insertbackground="white",
)
E.place(x=75, y=415)

matrices = {
    "a": Matrix([[3, 2, 1], [1, 1, 3], [0, 2, 1]]),
    "b": Matrix([[2, 1], [1, 0], [3, 2]])
}
state = "idle"
contMat = 2
nombreActual = ""
matrizActual = []


def insertarTexto(texto, start="\n"):
    global text
    text.config(state=NORMAL)
    text.insert(END, "{0}{1}".format(start, texto))
    text.see(END)
    text.config(state=DISABLED)
Ejemplo n.º 16
0
 def _logistic(x):
     r = Matrix(1, 2)
     for row, col, elem in x.elements():
         r[row][col] = 1.0 / (1 + math.exp(-elem))
     return r
Ejemplo n.º 17
0
 def __init__(self):
     self.l1 = Matrix(16, 16)
     self.b1 = Matrix(1, 16)
     self.l2 = Matrix(16, 4)
     self.b2 = Matrix(1, 4)
Ejemplo n.º 18
0
                num += 1


class Body(tk.Frame):
    def __init__(self, master):
        super().__init__(master)
        self.master = master
        self.master.place(relx=0.45, rely=0.05)
        background_image = tk.PhotoImage(
            file=r'C:\Python3\Lib\site-packages\pymatrix\head.gif')
        self.widget = tk.Label(master, image=background_image)
        self.widget.pack()


if __name__ == '__main__':
    m = Matrix([[98 * 5, 98 * (-2), 0], [-2 * 98, 3 * 98, -98], [0, -98, 98]])
    oper = Operation()
    mr = Spmatrix().diagonal(3, 0.27)
    a = oper.mul(oper.inverse(mr), m)
    for i in range(len(a)):
        for j in range(len(a)):
            a.matrix[i][j] = round(a.matrix[i][j], 2)
    print('原始矩阵为:', a)
    find = oper.feature_matrix(a, 3, e=0.1)
    # print(oper.feature_matrix(m, 3, e=0.1))
    # print('特征矩阵:', find['eigenvector'])
    print('特征值', find['eigenvalues'])

    # vector = [[3, 4, 5]]
    # s = Spmatrix()
    # print(isinstance(s, Matrix))