youssef
youssef

Reputation: 113

ValueError: shapes (3,) and (0,) not aligned: 3 (dim 0) != 0 (dim 0)

I have a text file of (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)

Upvotes: 0

Views: 901

Answers (1)

PiEmmeC
PiEmmeC

Reputation: 59

Because you are doing np.dot(n,p), these two elements have to be of the same dimention (as explained in the numpy documentation).

p is obtained from:

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(). The ValueError says this object is zero dimensional, so there is a problem in 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().

Upvotes: 1

Related Questions