简体   繁体   中英

How can I extract multiple elements from a column matrix (Python)?

Say if I have a column matrix

n =  
[[0.649100404993098]
 [0.548818798116734]
 [-0.526750976336541]]

I want to assign the values of n to x,y and z. For example x= 0.649100404993098, y=0.548818798116734, z=-0.526750976336541 . If I do x,y,z =n , then they are assigned as a list with desired values. How can I directly assign the values to x,y and z? Thanks:)

PS: The code I'm running is

b= 9.166801286935154 ,c= 7.750592706723353 ,d= -7.438943945547988
sig = np.matrix([[b],[c],[d]])
n = np.dot(1/sqrt(b**2+c**2+d**2),sig)
nx, ny, nz = [i for i in n]

You can try this if you're sure that the length of each element is 1:

nx, ny, nz = [i.item() for i in n]

You can get it with:

x, y, z = [i[0] for i in n]

If you have more than one column you could make it i[j] where j is the column index.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM