我需要将这个片段从python转换为c#:
def _get_w_matrix(quaternions):
w_matrix = [[[q[3], q[2], -q[1], q[0]],
[-q[2], q[3] , q[0], q[1]],
[q[1], -q[0], q[3], q[2]],
[-q[0], -q[1], -q[2], q[3]]] for q in quaternions] 其中四元数类似于
[[0. 0. 0. 0.]
[0. 2. 2. 0.]
[2. 3. 1. 0.]]我不明白返回哪种类型的对象,以及如何将其写下来。
编辑:我正在为.NET使用Numpy,所以在我的c#代码中,变量四元数是NDarray类型的。
发布于 2021-04-08 20:14:33
Python type()函数和print()函数是两个可以用来调试w_matrix list外观和类型的函数。
我编写这段代码是为了调试:
def _get_w_matrix(quaternions):
w_matrix = [[[q[3], q[2], -q[1], q[0]],
[-q[2], q[3] , q[0], q[1]],
[q[1], -q[0], q[3], q[2]],
[-q[0], -q[1], -q[2], q[3]]] for q in quaternions]
return w_matrix
inputMatrix = [[0,0,0,0],
[0,2,2,0],
[2,3,1,0]]
test = _get_w_matrix(inputMatrix)
print("matrix created by function: ")
print(test)
print("type of matrix:")
print(type(test))返回:
matrix created by function:
[[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 2, -2, 0], [-2, 0, 0, 2], [2, 0, 0, 2], [0, -2, -2, 0]], [[0, 1, -3, 2], [-1, 0, 2, 3], [3, -2, 0, 1], [-2, -3, -1, 0]]]
type of matrix:
<class 'list'>类型是包含整数的列表的python列表。我不是c#的专家,但这应该与List>类似
https://stackoverflow.com/questions/67011194
复制相似问题