Search code examples
pythontypeerror

TypeError: float() argument must be a string or a real number, not 'list'


I am getting a type error when I run this code. Please help me and thanks in advance.

input_delta = input("Enter your coordinate: ")
Delta_coordinates = [float(x) for x in [input_delta.split(",")]]
a = np.zeros((3, 3), int)
np.fill_diagonal(a, 100)
rotation_matrix = np.matrix([[-0.8660, 0.8660, 0], [0.5, 0.5, -1], [1, 1, 1]])
delta_abc = a*Delta_coordinates
mul_inverse = np.linalg.inv(a)
print(mul_inverse)
car = rotation_matrix*mul_inverse
cartesian = car*delta_abc
print(cartesian)

Solution

  • Change

    [float(x) for x in [input_delta.split(",")]]
    

    to this,

    Delta_coordinates = [float(x) for x in input_delta.split(",")]
    

    input_delta.split(",") itself returns a list, you don't need to convert that into a list again.