Summary
SE3 can be built from a single 4x4 array, from a list of 4x4 arrays (its own internal representation for a sequence of poses), or from other SE3 objects, but not from a stacked (N, 4, 4) ndarray. That is the natural way to hold a pose sequence in NumPy-based code (for example the output of np.stack, or a trajectory loaded from a file), and it is the form that a number of Robotics Toolbox for Python (RTB) functions accept for pose trajectories.
Reproduction
import numpy as np
from spatialmath import SE3
A = SE3.Rx(0.3).A
arr = np.array([A, A, A]) # shape (3, 4, 4)
SE3(arr)
# ValueError: bad argument to constructor
s = SE3(arr, check=False)
len(s), s.A.shape
# (1, (3, 4, 4)) <- silently a malformed object: length 1, but .A is (3, 4, 4)
len(SE3([A, A, A])) # 3, a list of matrices works
Tested with spatialmath-python 1.1.18.
Why it matters
- With the default
check=True the error message does not say what is accepted.
- With
check=False the constructor silently returns a malformed object. In RTB this turned a user's (N, 4, 4) trajectory into an object that failed deep inside an IK solver with ValueError: operands could not be broadcast together with shapes (3,4) (3,), far from the cause.
Suggested behaviour
- Accept an ndarray with
ndim == 3 and shape[1:] == (4, 4) as a sequence of N poses, equivalent to SE3(list(arr)).
- For other unsupported shapes, raise an error that says which forms are accepted. Ideally this validation of the array shape (not the matrix contents) would also happen with
check=False, which would skip only the expensive checks that the matrices are valid SE(3).
This is an enhancement request, not a regression. RTB works around it by converting the array to a list of matrices before calling the constructor, so there is no urgency.
Summary
SE3can be built from a single 4x4 array, from a list of 4x4 arrays (its own internal representation for a sequence of poses), or from otherSE3objects, but not from a stacked(N, 4, 4)ndarray. That is the natural way to hold a pose sequence in NumPy-based code (for example the output ofnp.stack, or a trajectory loaded from a file), and it is the form that a number of Robotics Toolbox for Python (RTB) functions accept for pose trajectories.Reproduction
Tested with spatialmath-python 1.1.18.
Why it matters
check=Truethe error message does not say what is accepted.check=Falsethe constructor silently returns a malformed object. In RTB this turned a user's(N, 4, 4)trajectory into an object that failed deep inside an IK solver withValueError: operands could not be broadcast together with shapes (3,4) (3,), far from the cause.Suggested behaviour
ndim == 3andshape[1:] == (4, 4)as a sequence of N poses, equivalent toSE3(list(arr)).check=False, which would skip only the expensive checks that the matrices are valid SE(3).This is an enhancement request, not a regression. RTB works around it by converting the array to a list of matrices before calling the constructor, so there is no urgency.