ValueError: matmul: входной операнд 1 имеет несоответствие в основном измерении 0? - PullRequest
1 голос
/ 03 марта 2020

Я пытался реализовать случайный ход, используя «алгоритм поворота». Я получаю следующее сообщение об ошибке:

enter image description here

Я знаю, что я пытаюсь сделать матричное умножение матрицы с 3 строками и 1 столбец с матрицей с 3 столбцами и 1 строкой. Но я не смог решить проблему. Может ли кто-нибудь помочь мне с этим?

Вот код:


def pivot_move(self,angle):
    phi = np.array(2 * np.pi * np.random.rand(1)) # theta in degrees
    theta = np.array(np.arccos(1 - 2* np.random.rand(1))) # phi in degrees

    u_x = np.sin(theta) * np.cos(phi)
    u_y = np.sin(theta) * np.sin(phi)
    u_z = np.cos(theta)

    """ Initializing the rotation matrix"""
    R_xx = np.cos(angle) + np.power(u_x, 2) * (1 - np.cos(angle))
    R_xy = u_x * u_y * (1 - np.cos(angle)) - u_z * np.sin(angle)
    R_xz = u_x * u_z * (1 - np.cos(angle)) + u_y * np.sin(angle)

    R_yx = u_x * u_y * (1 - np.cos(angle) + u_z * np.sin(angle))
    R_yy = np.cos(angle) + np.power(u_y, 2) * (1 - np.cos(angle))
    R_yz = u_y * u_z * (1 - np.cos(angle)) - u_x * np.sin(angle)

    R_zx = u_x * u_z * (1 - np.cos(angle)) - u_y * np.sin(angle)
    R_zy = u_y * u_z * (1 - np.cos(angle)) + u_x * np.sin(angle)
    R_zz = np.cos(angle) + np.power(u_z, 2) * (1 - np.cos(angle))

    Rot = np.array([[R_xx, R_xy, R_xz], [R_yx, R_yy, R_yz], [R_zx, R_zy,R_zz]])
    print("Rot", Rot)
    print("Rot has shape: {}".format(Rot.shape))

    pivot = np.random.randint(N - 1) + 1

    pivot_pos = np.array(self.chain[pivot].pos)
    print("pivot pos:{}".format(pivot_pos.shape))
    for i in range(pivot+1, N):
        monomer_pos = np.array([self.chain[i].pos[0], self.chain[i].pos[1], self.chain[i].pos[2]])
        print("monmer", monomer_pos)
        print("monomer shape is:{}".format(monomer_pos.shape))
        self.chain[i].pos = np.matmul(Rot, (monomer_pos - pivot_pos)) + pivot_pos 
        print("chain", self.chain[i].pos)
    return self

Результаты выглядят так:

enter image description here

...