[英]ValueError: shapes (3,) and (0,) not aligned: 3 (dim 0) != 0 (dim 0)
I have a text file of (x, y, z).我有一个 (x, y, z) 的文本文件。 I want to perform the mentioned operation in the code but the shown error of shapes reveals and I don't know where is the problem.
我想在代码中执行上述操作,但显示的形状错误显示,我不知道问题出在哪里。 Any help!
任何帮助!
import numpy as np
n = np.array([0.9, 0.43, -0.01])
d = 6.03
with open("D:/Point cloud data/projection_test_data.txt", 'r') as f:
for line in f:
p = np.array([float(number) for number in f.readline().split()])
v = np.dot(n,p)
q = np.array(p - ((v + d)*n))
ValueError Traceback (most recent call last)
Input In [79], in <module>
3 p = np.array([float(number) for number in f.readline().split()])
4 print(p)
----> 5 v = np.dot(n,p)
6 q = np.array(p - ((v + d)*n))
7 lines = str(q)
File <__array_function__ internals>:5, in dot(*args, **kwargs)
ValueError: shapes (3,) and (0,) not aligned: 3 (dim 0) != 0 (dim 0)
Because you are doing np.dot(n,p), these two elements have to be of the same dimention (as explained in the numpydocumentation ).因为您正在执行 np.dot(n,p),所以这两个元素必须具有相同的维度(如 numpy文档中所述)。
p is obtained from: p 来自:
p = np.array([float(number) for number in f.readline().split()])
Where you are trying to make an array of floats for each element in the object f.readline().split().您试图为对象 f.readline().split() 中的每个元素创建一个浮点数组。 The ValueError says this object is zero dimensional, so there is a problem in f.readline().split().
ValueError 说这个对象是零维的,所以 f.readline().split() 有问题。
Edit: You are doing f.readline().split() even if you are in a for line in f
loop, maybe you want to do line.split()
instead of f.readline().split()
.编辑:即使您
for line in f
,您也在做 f.readline().split() ,也许您想做line.split()
而不是f.readline().split()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.