简体   繁体   English

ValueError:形状(3,)和(0,)未对齐:3(dim 0)!= 0(dim 0)

[英]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.

相关问题 ValueError:形状和未对齐:(dim 2)!= 4(dim 0) - ValueError: shapes and not aligned: (dim 2) != 4 (dim 0) ValueError: 形状 (2,) 和 (5,) 未对齐:2 (dim 0) != 5 (dim 0) - ValueError: shapes (2,) and (5,) not aligned: 2 (dim 0) != 5 (dim 0) ValueError:形状 (1,6) 和 (5,5) 未对齐:6 (dim 1) != 5 (dim 0) - ValueError: shapes (1,6) and (5,5) not aligned: 6 (dim 1) != 5 (dim 0) Numpy ValueError:形状 (4,4) 和 (3,) 未对齐:4 (dim 1) != 3 (dim 0) - Numpy ValueError: shapes (4,4) and (3,) not aligned: 4 (dim 1) != 3 (dim 0) ValueError:形状(1,1)和(4,1)未对齐:1(dim 1)!= 4(dim 0) - ValueError: shapes (1,1) and (4,1) not aligned: 1 (dim 1) != 4 (dim 0) ValueError: 形状 (62,6) 和 (5,) 未对齐:6 (dim 1) != 5 (dim 0) - ValueError: shapes (62,6) and (5,) not aligned: 6 (dim 1) != 5 (dim 0) ValueError:形状(2,2)和(4,6)不对齐:2(dim 1)!= 4(dim 0) - ValueError: shapes (2,2) and (4,6) not aligned: 2 (dim 1) != 4 (dim 0) ValueError:形状(4,4)和(3,)不对齐:4(dim 1)!= 3(dim 0) - ValueError: shapes (4,4) and (3,) not aligned: 4 (dim 1) != 3 (dim 0) ValueError:形状(4,1)和(3,1)未对齐:1(dim 1)!= 3(dim 0) - ValueError: shapes (4,1) and (3,1) not aligned: 1 (dim 1) != 3 (dim 0) ValueError:形状 (3,3,1) 和 (3,1) 未对齐:1 (dim 2) != 3 (dim 0) - ValueError: shapes (3,3,1) and (3,1) not aligned: 1 (dim 2) != 3 (dim 0)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM