如何解决Python 到 C# 多维数组
我需要将这段代码从 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[2]],[-q[0],-q[2],q[3]]] for q in quaternions]
其中四元数类似于
[[0. 0. 0. 0.]
[0. 2. 2. 0.]
[2. 3. 1. 0.]]
我不明白返回的是哪种类型的对象以及如何写下来。
编辑: 我将 Numpy 用于 .NET,因此在我的 c# 代码中,变量四元数的类型为 NDarray。
解决方法
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[2]],[-q[0],-q[2],q[3]]] for q in quaternions]
return w_matrix
inputMatrix = [[0,0],[0,2,[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,-2,[-2,2],-3,[-1,3],[3,1],-1,0]]]
type of matrix:
<class 'list'>
类型是带有整数的列表列表的python列表。我不是 c# 专家,但这应该对应于类似 List>>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。