0

Please tell me how to convert numpy to sympy.

unit vector

not numpy. sympy only

import numpy as np
x = (2,0,0)
print("#",x)
y = np.array(list(x))
z = y/np.linalg.norm(y.astype('float'))
print("#",tuple(z))
# (2, 0, 0)
# (1.0, 0.0, 0.0)

I tried:

from sympy import *
def myUnitVector(myPoint3D):
    myL=myPoint3D.distance((0, 0))
    return Point3D(myPoint3D.x/myL,myPoint3D.y/myL,myPoint3D.z/myL)
x = (1,1,1)
print("#",Point3D(x))
print("#",myUnitVector(Point3D(x)))
print("#",myUnitVector(Point3D(x)).evalf())
print("#",myUnitVector(Point3D(x)).distance((0, 0)))
print("#",myUnitVector(Point3D(x)).evalf().distance((0, 0)))
# Point3D(1, 1, 1)
# Point3D(sqrt(3)/3, sqrt(3)/3, sqrt(3)/3)
# Point3D(0.577350269189626, 0.577350269189626, 0.577350269189626)
# 1
# 1.00000000000000
karel
  • 5,489
  • 46
  • 45
  • 50
mrrclb46z
  • 89
  • 6

0 Answers0