Posts: 163 
	Threads: 60 
	Joined: Jun 2022
	
 Reputation: 
 0
	 
 
	
		
		
		08-30-2023, 08:04 PM 
(This post was last modified: 09-04-2023, 04:29 PM by Albert.)
		
	 
	
		`numpy.asarray(rm.Mat)` returns the original matrix, transposed. This property is not reversed when casting back using `rm.Mat(numpy.ndarray)`. 
To reproduce:
 Code: import numpy as np 
from robodk import robomath 
A = robomath.eye() 
A[0,3] = 1 
A
 Quote:Pose(1.000, 0.000, 0.000,  0.000, 0.000, 0.000): 
[[ 1, 0, 0, 1 ], 
[ 0, 1, 0, 0 ], 
[ 0, 0, 1, 0 ], 
[ 0, 0, 0, 1 ]] 
Quote:array([[1, 0, 0, 0], 
      [0, 1, 0, 0], 
      [0, 0, 1, 0], 
      [1, 0, 0, 1]]) 
Code: A = robomath.Mat(A) 
A
 Quote:Matrix: (4, 1) 
[[ [1 0 0 0] ], 
[ [0 1 0 0] ], 
[ [0 0 1 0] ], 
[ [1 0 0 1] ]] 
	 
	
	
	
		
	 
 
 
 
	
	
	
		
	Posts: 163 
	Threads: 60 
	Joined: Jun 2022
	
 Reputation: 
 0
	 
 
	
	
		Bumping this thread. Should I open an issue on GitHub?
	 
	
	
	
		
	 
 
 
 
	
	
	
		
	Posts: 4,469 
	Threads: 2 
	Joined: Apr 2018
	
 Reputation: 
 208
	 
 
	
		
		
		09-07-2023, 04:51 PM 
(This post was last modified: 09-08-2023, 02:23 PM by Albert.)
		
	 
	
		I would not say this is a bug but maybe something we could have done better by design. Changing this behavior could brake many other things and break backwards compatibility. 
Instead, we could add this function to the Mat class. Example:
 Code: def toNumpy(self): 
    return np.asarray(self.tr())
 So so that we can do:
 Code: pose_mat = transl(10,20,30) 
pose_np = pose_mat.toNumpy() 
pose_mat2 = Mat(pose_np) 
# the 3 poses should be the same
 Woudl this work?
	  
	
	
	
		
	 
 
 
 
	
	
	
		
	Posts: 163 
	Threads: 60 
	Joined: Jun 2022
	
 Reputation: 
 0
	 
 
 
 
	
	
	
		
	Posts: 4,469 
	Threads: 2 
	Joined: Apr 2018
	
 Reputation: 
 208
	 
 
	
	
		Great then, we just added fromNumpy and toNumpy functions to convert to a numpy array and from a numpy array. 
Code:     def fromNumpy(ndarray): 
        """Convert a numpy array to a Mat matrix""" 
        return Mat(ndarray.tolist()) 
 
    def toNumpy(self): 
        """Return a copy of the Mat matrix as a numpy array""" 
        import numpy 
        return numpy.asarray(self.rows, float)
 You can find the latest version of the source code on our GitHub repository:
 https://github.com/RoboDK/RoboDK-API/tre...hon/robodk
	 
	
	
	
		
	 
 
 
 
	
	
	
		
	Posts: 163 
	Threads: 60 
	Joined: Jun 2022
	
 Reputation: 
 0
	 
 
 
 
	
	
	
		
	Posts: 337 
	Threads: 2 
	Joined: Jun 2021
	
 Reputation: 
 26
	 
 
 
 
	 
 |