Python converts a 10*2 randomly generated Cartesian coordinates (rectangular coordinates) into polar coordinates

created at 07-02-2021 views: 1

here is an example code block to converts a 10*2 randomly generated Cartesian coordinates (rectangular coordinates) into polar coordinates:

import math
import numpy as np
a10=np.random.random(20)
a10.shape=10,2
a=[]
print(a10)
def qiur(x,y):
    r=np.sqrt(x*x+y*y)
    return r
def qiuQ(x,y):
    Q=np.arctan(y/x)*180/math.pi
    return Q
for x,y in zip(a10[:,0],a10[:,1]):
    a.append(qiur(x,y))
    a.append(qiuQ(x,y))
a=np.array(a)
a.shape=10,2
print(a)
x1=qiur(1,1)
y1=qiuQ(1,1)
print(x1,y1)
Please log in to leave a comment.