显示ValueError:形状(1,3)和(1,3)不对齐:3(dim 1)!= 1(dim 0) [英] Showing ValueError: shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0)

查看:1419
本文介绍了显示ValueError:形状(1,3)和(1,3)不对齐:3(dim 1)!= 1(dim 0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下矩阵并执行点积,如代码所示.我检查了矩阵的大小,所有矩阵都是(3,1),但是最后两个点积对我来说是个错误.

I am trying to use the following matrices and perform a dot product as shown in the code. I checked the size of the matrices and all are (3, 1) but it is throwing me error for the last two dot products.

coordinate1 = [-7.173, -2.314, 2.811] 
coordinate2 = [-5.204, -3.598, 3.323] 
coordinate3 = [-3.922, -3.881, 4.044] 
coordinate4 = [-2.734, -3.794, 3.085] 

import numpy as np 
from numpy import matrix
coordinate1i=matrix(coordinate1)
coordinate2i=matrix(coordinate2)
coordinate3i=matrix(coordinate3)
coordinate4i=matrix(coordinate4)

b0 = coordinate1i - coordinate2i
b1 = coordinate3i - coordinate2i
b2 = coordinate4i - coordinate3i

n1 = np.cross(b0, b1)
n2 = np.cross(b2, b1)

n12cross = np.cross(n1,n2)
x1= np.cross(n1,b1)/np.linalg.norm(b1)
print np.shape(x1)
print np.shape(n2)
np.asarray(x1)
np.asarray(n2)

y = np.dot(x1,n2)
x = np.dot(n1,n2)

return np.degrees(np.arctan2(y, x))

推荐答案

通过使用

n12 = np.squeeze(np.asarray(n2))

X12 = np.squeeze(np.asarray(x1))

解决了这个问题.

这篇关于显示ValueError:形状(1,3)和(1,3)不对齐:3(dim 1)!= 1(dim 0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆